]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util: get rid of json_array_append
authorEric Leblond <eric@regit.org>
Fri, 4 Mar 2016 17:04:31 +0000 (18:04 +0100)
committerEric Leblond <eric@regit.org>
Mon, 7 Mar 2016 22:12:07 +0000 (23:12 +0100)
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
src/util-profiling-rules.c

index fb2c04f649eb0530628c55b327f2d98d3a7bb1ac..9332fcec4f5c641a880cb8363e4cd2ba08246d8f 100644 (file)
@@ -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++;
     }
 
index 3d679384bbedb08e7a8f359d499c0984813a2821..870f7b9705fe15f4f931557a07a444068cfaa665 100644 (file)
@@ -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);