In my code I have somewhere an uninitialized pointer that seems to get freed. The project is quite large and I cannot find the value. The problem is: once I attach a debugger, memory seems to be initialized with zero causing the pointer to be
free not causing trouble. Is there a way to initialize the memory when using GDB with something like
Is there a way to initialize the memory when using GDB with something like 0xDEADBEEF
Sure, if you know it's address:
(gdb) call memset($addr, 0xCC, $size) or
(gdb) set *(int*)$addr = 0xDEADBEEF.
The problem is usually that you don't know where that uninitialized pointer will be in memory.
One way to find it is with Memory Sanitizer.
Another way is to figure out whether this pointer is global, on stack, or on heap, where it is supposed to be initialized, and set access watchpoint on it with the awatch command.
P.S. You seem pretty convinced that your problem is "free uninitialized", but the symptoms of "double free" are often similar. I would try Address Sanitizer before doing anything else.
User contributions licensed under CC BY-SA 3.0