From fab0e59c70bfd8e39189ac29b17333d85d4645cb Mon Sep 17 00:00:00 2001 From: Hadriel Kaplan Date: Thu, 20 Aug 2015 14:38:35 -0400 Subject: Fix memory leaks of dumper SHB and IDB infos Change-Id: I6b81d3e853d503c6a81f9793957b48ab34c6808c Reviewed-on: https://code.wireshark.org/review/10156 Petri-Dish: Hadriel Kaplan Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- wiretap/wtap.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'wiretap/wtap.h') diff --git a/wiretap/wtap.h b/wiretap/wtap.h index 4c53b8706c..8de0c30898 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -1735,6 +1735,21 @@ void wtap_write_shb_comment(wtap *wth, gchar *comment); WS_DLL_PUBLIC wtapng_iface_descriptions_t *wtap_file_get_idb_info(wtap *wth); +/** + * @brief Free's a interface description block and all of its members. + * + * @details This free's all of the interface descriptions inside the passed-in + * struct, including their members (e.g., comments); and then free's the + * passed-in struct as well. + * + * @warning Do not use this for the struct returned by + * wtap_file_get_idb_info(), as that one did not create the internal + * interface descriptions; for that case you can simply g_free() the new + * struct. + */ +WS_DLL_PUBLIC +void wtap_free_idb_info(wtapng_iface_descriptions_t *idb_info); + /** * @brief Gets a debug string of an interface description. * @details Returns a newly allocated string of debug information about @@ -1847,6 +1862,10 @@ wtap_dumper* wtap_dump_open(const char *filename, int file_type_subtype, int enc /** * @brief Opens a new capture file for writing. * + * @note The shb_hdr, idb_inf, and nrb_hdr arguments will be used until + * wtap_dump_close() is called, but will not be free'd by the dumper. If + * you created them, you must free them yourself after wtap_dump_close(). + * * @param filename The new file's name. * @param file_type_subtype The WTAP_FILE_TYPE_SUBTYPE_XXX file type. * @param encap The WTAP_ENCAP_XXX encapsulation type (WTAP_ENCAP_PER_PACKET for multi) @@ -1870,6 +1889,10 @@ wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snap /** * @brief Creates a dumper for an existing file descriptor. * + * @note The shb_hdr, idb_inf, and nrb_hdr arguments will be used until + * wtap_dump_close() is called, but will not be free'd by the dumper. If + * you created them, you must free them yourself after wtap_dump_close(). + * * @param file_type_subtype The WTAP_FILE_TYPE_SUBTYPE_XXX file type. * @param encap The WTAP_ENCAP_XXX encapsulation type (WTAP_ENCAP_PER_PACKET for multi) * @param snaplen The maximum packet capture length. -- cgit v1.2.3