aboutsummaryrefslogtreecommitdiffstats
path: root/ui/cli
diff options
context:
space:
mode:
authorMartin Kaiser <wireshark@kaiser.cx>2020-12-20 19:56:36 +0100
committerAndersBroman <a.broman58@gmail.com>2021-01-15 06:03:45 +0000
commit8e030dfbea87944a5d9a054116f8323d436d06a3 (patch)
tree8e9ca3f816adf1c10dc67b8a2998b5fc6cc2c7c0 /ui/cli
parentb2b66be42c3126ec896bd2085b334258938add62 (diff)
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.
Diffstat (limited to 'ui/cli')
-rw-r--r--ui/cli/tap-simple_stattable.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/ui/cli/tap-simple_stattable.c b/ui/cli/tap-simple_stattable.c
index ee8ec79e79..014d0c908a 100644
--- a/ui/cli/tap-simple_stattable.c
+++ b/ui/cli/tap-simple_stattable.c
@@ -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);