Reputation: 37
When I used memwatch with my program, I crashed as belows:
* Error in `./xxx': double free or corruption (out): 0x0a015650 * ...
Because this is commercial program. I cannot show my codes. But, Are their any known issues related memory corruptions in memwatch? I am using stdup() to create string memory and free it just after it is used. So there is no double free, I assured
Also when I used valgrind, it shows same error
==20929== Invalid free() / delete / delete[] / realloc() ==20929== at 0x402AC38: free (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) .... ==20929== Address 0xb3b5948 is 40 bytes inside a block of size 54 alloc'd ==20929== at 0x40299D8: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) ==20929== by 0x8060F40: mwMalloc (memwatch.c:893) ==20929== by 0x80614AC: mwStrdup (memwatch.c:1045) ...
One weired thing is that if i did not use memwatch, valgrind did not show any errors, also there is no crashes. So I suspect that there is any known issue in the memewatch's wrapper malloc or free.
* Updated 2014. 3. 3 *
I found the answer :-). Because I did not build the libraries used in my application at all. Only application was built with memwatch.c and memwatch.h. So the problem is that memory (mwMalloc) was created in the my application code and freed by a library. So, in my opinion, memwatch has this shortcoming because all libraries should be built with memwatch support again. But this is almost impossible. I think that, for speed, mtrace (glibc built-in) will be better or valgrind can be used for some cases.
Upvotes: 0
Views: 471
Reputation: 113
Do you send to free() the right pointer returned by malloc or your strdup call ? Try to print the addresses using "printf("%p\n", yourVar);" after creating your string then right before sending it to free. Is there any differences?
Upvotes: 0