Red Hat Bugzilla – Bug 184384
setlocale() calls free(NULL)
Last modified: 2007-11-30 17:07:09 EST
Description of problem:
setlocale() will under certain contions call free(NULL). This is not exactly a
bug in its own right, but it could indicate an unexpected state inside the
routine, and having such calls floating around makes it harder to track down
actual memory errors and leaks in a program.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. cc setlocale.c -ldmalloc -o setlocale
2. DMALLOC_OPTIONS=debug=0x2000000 ./setlocale
(Assuming dmalloc is installed. setlocale.c will be attached to this report.)
1141823485: 30: WARNING: tried to free(0) from 'ra=0xe9cdbf'
1141823485: 30: free: invalid pointer: from 'ra=0xe9cdbf'
1141823485: 30: ERROR: _chunk_free: pointer is null (err 20)
1141823485: 30: ending time = 1141823485, elapsed since start = 0:00:00
[ No output ]
I'm testing under RHEL 3 right now, but I've also seen it on other releases and
Part of the problem is that various functions in Gtk and Glib contain
setlocale() calls that trigger this problem.
Created attachment 125795 [details]
Note that we've run extensive tests of the type indicated above, and this is the
only instance of free(NULL) within the system libs encountered so far. This
suggests to me that the developers have generally tried to avoid freeing
NULL-pointers, which probably also means it was not done on purpose in this case.
I don't see how the tests could be extensive, there are hundreds of places
in glibc alone where free can be called with NULL and in all cases it relies
on the ISO C99 22.214.171.124 mandated behavior of free - if ptr is a null pointer,
no action occurs.