forked from osmocom/wireshark
tap-simple_stattable: fix a memory leak for tshark -z
Displaying statistics with tshark results in a memory leak. tshark -r <any pcap file> -z dhcp,stat -q ==26971==ERROR: LeakSanitizer: detected memory leaks Direct leak of 24 byte(s) in 1 object(s) allocated from: #0 0x7f89a4bae518 in calloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0xe9518) #1 0x7f8989af2918 in g_malloc0 (/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x53918) init_stat_table allocates a table_stat_t. This is used as private data while the tap listener is running but it's not freed afterwards. This patch adds a finish callback for the tap listener where the table_stat_t is freed.
This commit is contained in:
parent
b2b66be42c
commit
8e030dfbea
|
@ -89,6 +89,13 @@ simple_draw(void *arg)
|
|||
printf("=====================================================================================================\n");
|
||||
}
|
||||
|
||||
static void simple_finish(void *tapdata)
|
||||
{
|
||||
stat_data_t *stat_data = (stat_data_t *)tapdata;
|
||||
|
||||
g_free(stat_data->user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
init_stat_table(stat_tap_table_ui *stat_tap, const char *filter)
|
||||
{
|
||||
|
@ -102,7 +109,9 @@ init_stat_table(stat_tap_table_ui *stat_tap, const char *filter)
|
|||
|
||||
stat_tap->stat_tap_init_cb(stat_tap);
|
||||
|
||||
error_string = register_tap_listener(stat_tap->tap_name, &ui->stats, filter, 0, NULL, stat_tap->packet_func, simple_draw, NULL);
|
||||
error_string = register_tap_listener(stat_tap->tap_name, &ui->stats,
|
||||
filter, 0, NULL, stat_tap->packet_func, simple_draw,
|
||||
simple_finish);
|
||||
if (error_string) {
|
||||
/* free_rtd_table(&ui->rtd.stat_table); */
|
||||
cmdarg_err("Couldn't register tap: %s", error_string->str);
|
||||
|
|
Loading…
Reference in New Issue