diff options
author | Peter Wu <peter@lekensteyn.nl> | 2016-09-10 01:12:58 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2016-09-10 12:59:47 +0000 |
commit | ba2a3b3626ef9fc084ee8a9508d196ec890c2336 (patch) | |
tree | 7351cf899d7502a14d90bca53a70799ca5e6f309 | |
parent | d6f91a7ca421caa7787c1539bca61f943923fa9c (diff) | |
download | wireshark-ba2a3b3626ef9fc084ee8a9508d196ec890c2336.tar.gz |
wiretap: fix memory leak of interface_data for wtap_dumper
Mirrors the behavior of wtap_close.
Change-Id: I1a04878fdd0409fa74931737332f9b8a1ae77fb1
Reviewed-on: https://code.wireshark.org/review/17620
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
-rw-r--r-- | wiretap/file_access.c | 4 | ||||
-rw-r--r-- | wiretap/wtap.h | 11 |
2 files changed, 12 insertions, 3 deletions
diff --git a/wiretap/file_access.c b/wiretap/file_access.c index 434ec12490..eda6c492d9 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -2204,7 +2204,8 @@ wtap_dump_init_dumper(int file_type_subtype, int encap, int snaplen, gboolean co if ((idb_inf != NULL) && (idb_inf->interface_data->len > 0)) { guint itf_count; - /* XXX: what free's this stuff? */ + /* Note: this memory is owned by wtap_dumper and will become + * invalid after wtap_dump_close. */ wdh->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); for (itf_count = 0; itf_count < idb_inf->interface_data->len; itf_count++) { file_int_data = g_array_index(idb_inf->interface_data, wtap_block_t, itf_count); @@ -2574,6 +2575,7 @@ wtap_dump_close(wtap_dumper *wdh, int *err) } if (wdh->priv != NULL) g_free(wdh->priv); + wtap_block_array_free(wdh->interface_data); g_free(wdh); return ret; } diff --git a/wiretap/wtap.h b/wiretap/wtap.h index 7a8b1d94c2..63787292ba 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -1713,9 +1713,11 @@ void wtap_fdclose(wtap *wth); WS_DLL_PUBLIC gboolean wtap_fdreopen(wtap *wth, const char *filename, int *err); -/*** close the current file ***/ +/** Close only the sequential side, freeing up memory it uses. */ WS_DLL_PUBLIC void wtap_sequential_close(wtap *wth); + +/** Closes any open file handles and frees the memory associated with wth. */ WS_DLL_PUBLIC void wtap_close(wtap *wth); @@ -1874,8 +1876,13 @@ void wtap_set_bytes_dumped(wtap_dumper *wdh, gint64 bytes_dumped); struct addrinfo; WS_DLL_PUBLIC gboolean wtap_dump_set_addrinfo_list(wtap_dumper *wdh, addrinfo_lists_t *addrinfo_lists); + +/** + * Closes open file handles and frees memory associated with wdh. Note that + * shb_hdr, idb_inf and nrb_hdr are not freed by this routine. + */ WS_DLL_PUBLIC -gboolean wtap_dump_close(wtap_dumper *, int *); +gboolean wtap_dump_close(wtap_dumper *wdh, int *err); /** * Return TRUE if we can write a file out with the given GArray of file |