Why do we cast return value of malloc? [duplicate]

No need to cast return value of malloc as its return type is void*. Can someone explain why do some programmers use (char *) in front of the malloc? They are doing wrong (most probably) by casting it (in good programmers opinion). As wiki says: malloc returns a void pointer (void *), which indicates that … Read more

How to find the cause of a malloc “double free” error?

When an object is “double-freed”, the most common cause is that you’re (unnecessarily) releasing an autoreleased object, and it is later autoreleased when the containing autorelease pool is emptied. I’ve found that the best way to track down the extra release is to use the NSZombieEnabled environment variable for the affected executable in Xcode. For … Read more

How to use realloc in a function in C

You want to modify the value of an int* (your array) so need to pass a pointer to it into your increase function: void increase(int** data) { *data = realloc(*data, 5 * sizeof int); } Calling code would then look like: int *data = malloc(4 * sizeof *data); /* do stuff with data */ increase(&data); … Read more

Include source code of malloc.c in gdb?

The following worked for me. Not sure whether there is a better way. Install libc6-dbg (which you have already done): sudo apt-get install libc6-dbg Install the eglibc-source package (ubuntu actually uses eglibc): sudo apt-get install eglibc-source. Unpack the tar file that was installed in /usr/src/glibc: /usr/src/glibc $ sudo tar xvf eglibc-2.19.tar.xz Crank up gdb and … Read more