[Chilli] [PATCH] Fix: Memory leak of opt_run()

Masashi Honma honma at ictec.co.jp
Fri Mar 5 05:53:35 UTC 2010


Hello.

The opt_run() passes arguments to chilli_opt. But the arguments can't
be freed because the process calls execl() after calloc(). This patch
replaces calloc() with array.


Index: options.c
===================================================================
--- options.c	(revision 297)
+++ options.c	(working copy)
@@ -115,11 +115,17 @@
 }
 
 static int opt_run(int argc, char **argv, int reload) {
-  char **newargs;
+#define OPT_ARG_SIZE 16
+  char *newargs[OPT_ARG_SIZE];
   char file[128];
   int status;
   int i;
 
+  if (argc + 4 > OPT_ARG_SIZE) {
+    log_err(0, "argument too much");
+    return -1;
+  }
+
   chilli_binconfig(file, sizeof(file), 0);
 
   log_dbg("(Re)processing options [%s]", file);
@@ -133,10 +139,6 @@
     return status;
   }
 
-  if (!(newargs = calloc(1, sizeof(char *) * (argc + 4)))) {
-    return -1;
-  }
-  
   for (i=1; i < argc; i++) {
     newargs[i] = argv[i];
   }
@@ -145,6 +147,7 @@
   newargs[i++] = "-b";
   newargs[i++] = file;
   newargs[i++] = reload ? "-r" : NULL;
+  newargs[i++] = NULL;
 
   log_dbg("running chilli_opt on %s", file);
 


Regards,
Masashi Honma.


More information about the Chilli mailing list