Is there any way to squelch the output that glibc generates when there is memory corruption? Here's what I'm seeing
make
*** glibc detected *** /home/myname/php/sapi/cli/php: free(): invalid pointer: x0045d67f ***
======= Backtrace: =========
/lib/libc.so.6(+0x6eb41)[0x380b41]
<snip>
======= Memory map: ========
00115000-00116000 r-xp 00000000 00:00 0 [vdso]
001d7000-001ee000 r-xp 00000000 ca:01 540738 /lib/libpthread-2.12.2.so
001ee000-001ef000 r--p 00016000 ca:01 540738 /lib/libpthread-2.12.2.so
001ef000-001f0000 rw-p 00017000 ca:01 540738 /lib/libpthread-2.12.2.so
<snip>
For the work I am doing, I couldn't care less about this info, it only matters that the make did not succeed (return value != 0). These messages are filling up the screen and it makes the rest of my output unreadable. I have tried:
make &> /dev/null
{ make ; } &> /dev/null
x=`make 2>&1` &> /dev/null
but none of them catch the output. If it isn't being written to stderr, where the heck is it coming from? I'd like a solution that doesn't require rebuilding glibc, if possible.
Here is some code which will give such an error message, but note this has nothing to do with the code I am working on (the php source code). I just want to silence this type of output from my console.
int main()
{
char* ptr = (char*)malloc(sizeof("test"));
char array[]= "test";
ptr = array;
free(ptr);
return 0;
}
Yes: run your code with the environment variable MALLOC_CHECK_
(the trailing underscore is deliberate) set to 0
.
This is partially documented in the libc manual, although there seem to be more options than just the 0
, 1
or 2
which are suggested there. (The value ends up being passed as the action
argument to malloc_printerr()
in glibc's malloc/malloc.c
, and the default value seems to be 3
.)
The reason you can't redirect it is that it gets written specifically to /dev/tty
, unless you have set the environment variable LIBC_FATAL_STDERR_
. (I'm not sure this is documented anywhere, but the relevant code can be found here.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With