From: Konrad Kuchciak Date: Fri, 13 Nov 2020 09:18:45 +0000 (+0100) Subject: Fix leaking memory X-Git-Tag: submit/tizen/20201113.104418~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cee09112f3525c64001f112698b480e653ff75d3;p=platform%2Fcore%2Fsystem%2Fstability-monitor.git Fix leaking memory Change-Id: Ibcfec9b78deb12554db06562b9bd93639c507ceb --- diff --git a/src/process.c b/src/process.c index 7b419c1..e6f9001 100644 --- a/src/process.c +++ b/src/process.c @@ -429,25 +429,26 @@ static void _print_header(struct proc_info *process) { struct data_source *ds; int ds_n = data_sources_get_n(); - int header_lines = 2; - gchar **header_items = g_new(gchar *, (ds_n + 1) * header_lines); + gchar **header_items[2]; gchar *str = NULL; + for (size_t i = 0; i < sizeof(header_items)/sizeof(header_items[0]); i++) + header_items[i] = g_new(gchar *, ds_n + 1); + for (int i = 0; i < ds_n; i++) { ds = &(process->data_sources[i]); - header_items[(ds_n + 1) * 0 + i] = g_strdup_printf("%s%-20s", i > 0 ? " | " : "", ds->param_name); - header_items[(ds_n + 1) * 1 + i] = g_strdup_printf("%s%-10s%-10s", i > 0 ? " | " : "", "peak ---- ", "avg ------"); + header_items[0][i] = g_strdup_printf("%s%-20s", i > 0 ? " | " : "", ds->param_name); + header_items[1][i] = g_strdup_printf("%s%-10s%-10s", i > 0 ? " | " : "", "peak ---- ", "avg ------"); } /* Print the header line by line */ - for (int i = 0; i < header_lines; i++) { - header_items[(ds_n + 1) * i + ds_n] = NULL; - str = g_strjoinv(NULL, &header_items[(ds_n + 1) * i]); + for (size_t i = 0; i < sizeof(header_items)/sizeof(header_items[0]); i++) { + header_items[i][ds_n] = NULL; + str = g_strjoinv(NULL, header_items[i]); _I_PROC(process, "%s", str); g_free(str); + g_strfreev(header_items[i]); } - - g_strfreev(header_items); } void process_print_current_state(struct proc_info *process) @@ -456,7 +457,7 @@ void process_print_current_state(struct proc_info *process) struct smpl_container *sc; struct sample_s *last_sample; int ds_n = data_sources_get_n(); - gchar **state_items = g_new(gchar *, ds_n); + gchar **state_items = g_new(gchar *, ds_n + 1); gchar *avg_item; gchar *state_msg = NULL; static unsigned long long last_msg_count = 0;