aboutsummaryrefslogtreecommitdiffstats
path: root/ui/tap_export_pdu.c
diff options
context:
space:
mode:
authorVasil Velichkov <vvvelichkov@gmail.com>2018-08-03 02:17:07 +0300
committerAnders Broman <a.broman58@gmail.com>2018-08-03 09:27:06 +0000
commit51299192e214d025d5d759bce776104a0f2a6ffc (patch)
treee0813a8128fe5193aeaa4f357838d5d554259373 /ui/tap_export_pdu.c
parent71759a7130b4aae10f31e9cdb3eabdcfa611730d (diff)
tap_export_pdu: Fix two memory leaks
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>
Diffstat (limited to 'ui/tap_export_pdu.c')
-rw-r--r--ui/tap_export_pdu.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/ui/tap_export_pdu.c b/ui/tap_export_pdu.c
index f385499674..6865b0c839 100644
--- a/ui/tap_export_pdu.c
+++ b/ui/tap_export_pdu.c
@@ -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;
}