This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/19039] argp leaks memory when argp.options is a non-NULL array of zero length


https://sourceware.org/bugzilla/show_bug.cgi?id=19039

--- Comment #1 from Kenny Stauffer <kstauffer at gmail dot com> ---
The leaked memory is allocated here:

argp-help.c:make_hol
      hol->entries = malloc (sizeof (struct hol_entry) * hol->num_entries);
      hol->short_options = malloc (num_short_options + 1);

When argp.options points to an array of zero length, num_entries is 0.

The leak happens here:

argp-help.c:hol_free
  if (hol->num_entries > 0)
    {
      free (hol->entries);
      free (hol->short_options);
    }

Of the many ways to fix this, perhaps the easiest would be to change make_hol
from this:

opts = argp.options;
...
if (opts)

To this:

opts = argp.options;
...
if (opts && ! oend (opts))

-- 
You are receiving this mail because:
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]