This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Free errstring if _dl_addr returns 0
> -- * dlfcn/dlerror.c (check_free): Free errstring if _dl_addr
> returns 0. Don't check if map is NULL.
MAP in caps.
> - always the C library in the base namespave. */
> + always the C library in the base namespace. _dl_addr retuns 0
Typo: "returns"
> + when check_free isn't called from any loaded object. This
> + indicates static executable and we can free the string. */
"This indicates we're in a static executable, in which case it's always
safe to free the string."
However, it occurs to me that we probably want a sanity check here. That
is, if _dl_addr returns 0 for some unexpected reason, we should not call
free. It should never be possible #ifdef SHARED, right?
Hmm. Why do this test dynamically rather than simply use #ifndef SHARED?
i.e.:
/* We can free the string only if the allocation happened in the
C library used by the dynamic linker. This means, it is
always the C library in the base namespace. When we're statically
linked, the dynamic linker is part of the program and so always
uses the same C library we use here. */
#ifndef SHARED
struct link_map *map = NULL;
Dl_info info;
if (_dl_addr (check_free, &info, &map, NULL) != 0 && map->l_ns == 0)
#endif
free ((char *) rec->errstring);
Is there any case where that would be wrong?
Thanks,
Roland