RPM Community Forums

Mailing List Message of <popt-devel>

Re: POPT's API has designed in memory leaks. What to do?

From: Jeff Johnson <n3npq@mac.com>
Date: Mon 14 Jun 2010 - 17:16:34 CEST
Message-id: <55AF640F-3529-4F64-AD74-E6FAACD9B812@mac.com>

On Jun 7, 2010, at 2:38 PM, Jeff Johnson wrote:
> AFAIK, all POPT args are either returned by value (like POPT_ARG_INT) or
> through malloc'd memory _ALWAYS_. The rules on table callbacks are different
> than the rules for the no-brainer, in-line loop based getopt(3) like processing.
> OTOH, some of the code paths in POPT are quite twisty, perhaps there's someplace
> where another strdup/malloc is needed.

Here is poptPeekArg() (I happen to have on my screen):

const char * poptPeekArg(poptContext con)
    const char * ret = NULL;
    if (con && con->leftovers != NULL && con->nextLeftover < con->numLeftovers)
        ret = con->leftovers[con->nextLeftover];
    return ret;

So no malloc with poptPeekArg() returns atm, largely for hysterical

Its easy enough to add strdup (or not) to poptPeekArg(). What isn't clear is
whether a consistent rule like
	All memory is malloc'd before return.
is preferred to the mysteriously inconsistent current behavior in POPT.

73 de Jeff
Received on Mon Jun 14 17:17:15 2010
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.