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

Masashi Honma honma at ictec.co.jp
Fri Mar 5 06:38:14 UTC 2010


(2010/03/05 15:04), David Bird wrote:
> 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?

Of course I did test about it like this.

static**newargs_bk;  <-- add

static int opt_run(int argc, char **argv, int reload) {
   char **newargs;
   char file[128];

   newargs_bk = newargs;  <-- add


void options_destroy() {
   if (_options._data)
     free(_options._data);
   free(newargs_bk);  <-- add
}

I backuped newargs to newargs_bk and freed newargs_bk in options_destroy().
The options_destroy() is called after "chilli_opt" process. (I checked this
order by inserting printf() before the final line of main() of "main-opt.c"
and options_destroy().) Linux kernel will output double free warning when
newargs_bk was freed in options_destroy() if the newargs_bk was freed
already. But no warning displayed. So I understood the memory is leaked.

Regards,
Masashi Honma.


More information about the Chilli mailing list