From 606ac17c5786c98953e8bf1f60d9c3546cd5b6cc Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Fri, 4 Mar 2016 18:04:31 +0100 Subject: [PATCH] util: get rid of json_array_append This function is causing a memleak because it is necessary to clean up after usage. This fixes at least: 37 (32 direct, 5 indirect) bytes in 1 blocks are definitely lost in loss record 104 of 394 at 0x4C29C0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x66D0C7B: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.7.0) by 0x943584: LiveDeviceIfaceList (util-device.c:264) by 0x910889: UnixCommandExecute (unix-manager.c:486) by 0x910D7E: UnixCommandRun (unix-manager.c:545) by 0x911193: UnixMain (unix-manager.c:593) by 0x913CC7: UnixManager (unix-manager.c:961) by 0x907753: TmThreadsManagement (tm-threads.c:600) by 0x68DE283: start_thread (pthread_create.c:333) by 0x80A6A4C: clone (in /lib/x86_64-linux-gnu/libc-2.21.so) --- src/util-device.c | 2 +- src/util-profiling-rules.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util-device.c b/src/util-device.c index fb2c04f649..9332fcec4f 100644 --- a/src/util-device.c +++ b/src/util-device.c @@ -261,7 +261,7 @@ TmEcode LiveDeviceIfaceList(json_t *cmd, json_t *answer, void *data) return TM_ECODE_FAILED; } TAILQ_FOREACH(pd, &live_devices, next) { - json_array_append(jarray, json_string(pd->dev)); + json_array_append_new(jarray, json_string(pd->dev)); i++; } diff --git a/src/util-profiling-rules.c b/src/util-profiling-rules.c index 3d679384bb..870f7b9705 100644 --- a/src/util-profiling-rules.c +++ b/src/util-profiling-rules.c @@ -334,7 +334,7 @@ static void DumpJson(FILE *fp, SCProfileSummary *summary, uint32_t count, uint64 double percent = (long double)summary[i].ticks / (long double)total_ticks * 100; json_object_set_new(jsm, "percent", json_integer(percent)); - json_array_append(jsa, jsm); + json_array_append_new(jsa, jsm); } } json_object_set_new(js, "rules", jsa);