[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: auto-apt-0.3.22 hurd patch (PATH_MAX)

On Thu, Jan 26, 2012 at 1:21 PM, Tanguy LE CARROUR
<tanguy.lecarrour@gmail.com> wrote:
> 2) The problem in pkg_symbol() is a bit different. The dynamically allocated
> buffer is the return value of the function, so I cannot free it in the
> function. The rest of the code that uses this buffer never frees it!
> Am I supposed to fix each part of the code that uses this function to free
> the returned buffer?!

Presumably the returned buffer is static.

You could use a static pointer to a buffer which is reallocated on
each call; from the exterior the semantics would be close to

    char *fun(void)
        static char *buf = NULL;
        buf = realloc(buf, whatever size is required this time);
        return buf;

You'll be fine as long as the calling code does not assume the
function returns a constant pointer.

Jérémie Koenig <jk@jk.fr.eu.org>

Reply to: