From d58567bd78abc1903191c9a955365b8d41f09496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig=20Bj=C3=B8rlykke?= Date: Wed, 5 Nov 2014 14:36:29 +0100 Subject: [PATCH] Fixed memory leakage in col_cleanup. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Several fields in cinfo is allocated memory and must be freed here to avoid memory leakage when recreating the packet list. Do not allocate memory for col_expr[] as this points to static strings or other allocated strings. Change-Id: I840377e3c590b1a3e2a38e0537465a028041d1e9 Reviewed-on: https://code.wireshark.org/review/5137 Petri-Dish: Stig Bjørlykke Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann Reviewed-by: Anders Broman --- epan/column-utils.c | 12 ++++++++++++ epan/column.c | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/epan/column-utils.c b/epan/column-utils.c index 8721dbfb19..0de9a7c914 100644 --- a/epan/column-utils.c +++ b/epan/column-utils.c @@ -42,6 +42,7 @@ #include #include #include +#include /* Allocate all the data structures for constructing column data, given the number of columns. */ @@ -77,6 +78,17 @@ col_setup(column_info *cinfo, const gint num_cols) void col_cleanup(column_info *cinfo) { + int i; + + for (i = 0; i < cinfo->num_cols; i++) { + g_free(cinfo->fmt_matx[i]); + g_free(cinfo->col_title[i]); + g_free(cinfo->col_custom_field[i]); + dfilter_free(cinfo->col_custom_dfilter[i]); + g_free(cinfo->col_buf[i]); + g_free(cinfo->col_expr.col_expr_val[i]); + } + g_free(cinfo->col_fmt); g_free(cinfo->fmt_matx); g_free(cinfo->col_first); diff --git a/epan/column.c b/epan/column.c index 24a35f5084..c5aacd9777 100644 --- a/epan/column.c +++ b/epan/column.c @@ -824,7 +824,7 @@ build_column_format_array(column_info *cinfo, const gint num_cols, const gboolea if(reset_fences) cinfo->col_fence[i] = 0; - cinfo->col_expr.col_expr[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN); + cinfo->col_expr.col_expr[i] = ""; cinfo->col_expr.col_expr_val[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN); }