On Thu, Jan 26, 2012 at 1:21 PM, Tanguy LE CARROUR <tanguy.lecarr...@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 identical: 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 <j...@jk.fr.eu.org> http://jk.fr.eu.org/ -- To UNSUBSCRIBE, email to debian-hurd-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/CA+kCSAbd+D+bLjw=njq2cfnuaxfyoraxwknw57knwcxmowu...@mail.gmail.com