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

David Bird david at coova.com
Fri Mar 5 06:04:05 UTC 2010


Does it really matter? While technically the memory I guess is leaked,
it is allocated in a forked process that is about to be replaced with
execl(). And, since the memory in question is holding the arguments, the
memory needs to be valid until the execl process exits. I believe the
heap and stack approaches are basically the same. Are you running a tool
that indicated the memory was a leaked?

On Fri, 2010-03-05 at 14:53 +0900, Masashi Honma wrote:
> 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.
> _______________________________________________
> Chilli mailing list
> Chilli at coova.org
> http://lists.coova.org/cgi-bin/mailman/listinfo/chilli




More information about the Chilli mailing list