]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Add wpabuf_clear_free() to allow clearing of freed memory
authorJouni Malinen <j@w1.fi>
Mon, 5 Jan 2015 16:02:04 +0000 (18:02 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 5 Jan 2015 16:02:04 +0000 (18:02 +0200)
This can be useful when a wpabuf is used to store private data that
should not be left in heap after use.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/utils/wpabuf.c
src/utils/wpabuf.h

index b257b365c756cd07cb746ed5824a09442c277e1a..7aafa0a5169ba775bd681850bffe21def1097518 100644 (file)
@@ -205,6 +205,15 @@ void wpabuf_free(struct wpabuf *buf)
 }
 
 
+void wpabuf_clear_free(struct wpabuf *buf)
+{
+       if (buf) {
+               os_memset(wpabuf_mhead(buf), 0, wpabuf_len(buf));
+               wpabuf_free(buf);
+       }
+}
+
+
 void * wpabuf_put(struct wpabuf *buf, size_t len)
 {
        void *tmp = wpabuf_mhead_u8(buf) + wpabuf_len(buf);
index dbce925ca1bbb42e362b037f664bd6c8211a3f2f..c3ef1bae3667a838706c9e642c674afd60728cc1 100644 (file)
@@ -32,6 +32,7 @@ struct wpabuf * wpabuf_alloc_ext_data(u8 *data, size_t len);
 struct wpabuf * wpabuf_alloc_copy(const void *data, size_t len);
 struct wpabuf * wpabuf_dup(const struct wpabuf *src);
 void wpabuf_free(struct wpabuf *buf);
+void wpabuf_clear_free(struct wpabuf *buf);
 void * wpabuf_put(struct wpabuf *buf, size_t len);
 struct wpabuf * wpabuf_concat(struct wpabuf *a, struct wpabuf *b);
 struct wpabuf * wpabuf_zeropad(struct wpabuf *buf, size_t len);