tap_export_pdu: Fix two memory leaks
authorVasil Velichkov <vvvelichkov@gmail.com>
Thu, 2 Aug 2018 23:17:07 +0000 (02:17 +0300)
committerAnders Broman <a.broman58@gmail.com>
Fri, 3 Aug 2018 09:27:06 +0000 (09:27 +0000)
253 (8 direct, 245 indirect) bytes in 1 blocks are definitely lost in loss record 87 of 93
   at 0x4C2EBAB: malloc (vg_replace_malloc.c:299)
   by 0xBC4B3C5: g_malloc (gmem.c:99)
   by 0x13E225: exp_pdu_open (tap_export_pdu.c:128)

372 (40 direct, 332 indirect) bytes in 1 blocks are definitely lost in loss record 88 of 93
   at 0x4C2EBAB: malloc (vg_replace_malloc.c:299)
   by 0xBC4B3C5: g_malloc (gmem.c:99)
   by 0xBC62FF6: g_slice_alloc (gslice.c:1025)
   by 0xBC16984: g_array_sized_new (garray.c:194)
   by 0x13E143: exp_pdu_open (tap_export_pdu.c:93)

Change-Id: I24a3cec1dc4491032232c282b01fea04a23872b3
Reviewed-on: https://code.wireshark.org/review/28934
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
ui/tap_export_pdu.c
ui/tap_export_pdu.h

index f3854996747e4f0e6d1e978deabd91b1fb0ad18e..6865b0c839d1c157d18caa969263fc8a62a491e6 100644 (file)
@@ -90,8 +90,6 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, char *comment)
 
     /* pcapng defs */
     wtap_block_t                 shb_hdr;
-    GArray                      *shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
-    wtapng_iface_descriptions_t *idb_inf;
     wtap_block_t                 int_data;
     wtapng_if_descr_mandatory_t *int_data_mand;
     GString                     *os_info_str;
@@ -125,8 +123,8 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, char *comment)
     wtap_block_add_string_option_format(shb_hdr, OPT_SHB_USERAPPL, "Wireshark %s", get_ws_vcs_version_info());
 
     /* Create fake IDB info */
-    idb_inf = g_new(wtapng_iface_descriptions_t,1);
-    idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
+    exp_pdu_tap_data->idb_inf = g_new(wtapng_iface_descriptions_t,1);
+    exp_pdu_tap_data->idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
 
     /* create the fake interface data */
     int_data = wtap_block_create(WTAP_BLOCK_IF_DESCR);
@@ -138,18 +136,19 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, char *comment)
     wtap_block_add_string_option(int_data, OPT_IDB_NAME, "Fake IF, PDU->Export", strlen("Fake IF, PDU->Export"));
     wtap_block_add_uint8_option(int_data, OPT_IDB_TSRESOL, 9);
 
-    g_array_append_val(idb_inf->interface_data, int_data);
+    g_array_append_val(exp_pdu_tap_data->idb_inf->interface_data, int_data);
 
-    g_array_append_val(shb_hdrs, shb_hdr);
+    exp_pdu_tap_data->shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
+    g_array_append_val(exp_pdu_tap_data->shb_hdrs, shb_hdr);
 
     if (fd == 1) {
         exp_pdu_tap_data->wdh = wtap_dump_open_stdout_ng(WTAP_FILE_TYPE_SUBTYPE_PCAPNG,
                 WTAP_ENCAP_WIRESHARK_UPPER_PDU, WTAP_MAX_PACKET_SIZE_STANDARD, FALSE,
-                shb_hdrs, idb_inf, NULL, &err);
+                exp_pdu_tap_data->shb_hdrs, exp_pdu_tap_data->idb_inf, NULL, &err);
     } else {
         exp_pdu_tap_data->wdh = wtap_dump_fdopen_ng(fd, WTAP_FILE_TYPE_SUBTYPE_PCAPNG,
                 WTAP_ENCAP_WIRESHARK_UPPER_PDU, WTAP_MAX_PACKET_SIZE_STANDARD, FALSE,
-                shb_hdrs, idb_inf, NULL, &err);
+                exp_pdu_tap_data->shb_hdrs, exp_pdu_tap_data->idb_inf, NULL, &err);
     }
     if (exp_pdu_tap_data->wdh == NULL) {
         g_assert(err != 0);
@@ -166,6 +165,9 @@ exp_pdu_close(exp_pdu_t *exp_pdu_tap_data)
     if (!wtap_dump_close(exp_pdu_tap_data->wdh, &err))
         g_assert(err != 0);
 
+    wtap_block_array_free(exp_pdu_tap_data->shb_hdrs);
+    wtap_free_idb_info(exp_pdu_tap_data->idb_inf);
+
     remove_tap_listener(exp_pdu_tap_data);
     return err;
 }
index d9ef6ed45ad8b5f5b823baf5670efcf1bf3fa6a5..ea5c4077e1095a8ba712af89047d698460a130e7 100644 (file)
@@ -18,6 +18,8 @@ extern "C" {
 typedef struct _exp_pdu_t {
     int          pkt_encap;
     wtap_dumper* wdh;
+    GArray* shb_hdrs;
+    wtapng_iface_descriptions_t* idb_inf;
 } exp_pdu_t;
 
 /**