When working with memory allocation, valgrind and gdb, I had to write a simple c program with an invalid free:
#include <stdlib.h>
#include <stdio.h>
int main (void)
{
int* arr = (void*) malloc(100 * sizeof(int));
arr[50] = 10;
free(arr + (20 * sizeof(int)));
printf("arr[50] = %d\n", arr[50]);
return 0;
}
What causes the error:
...
...
Then I tried to get rid of the output by redirecting to sdtout
and stderr
to /dev/null
, but noticed that the output would still be printed, which left me puzzled.
I stopped the program before calling free()
with the debugger, looked at the directory /proc/PID/fd
and tried again to redirect all the listed fd to /dev/null
, but still the same result.
I searched the Internet for answers and asked some of my colleagues, but no one could explain to me how this conclusion is printed and why it cannot be redirected.
, , /Linux, , , .
!