leak detection from library functions.(mxml)

158 views
Skip to first unread message

Mike Finch

unread,
Jan 6, 2014, 4:47:48 PM1/6/14
to cppu...@googlegroups.com
I read this and I am close.

I am using a "C" function from a library that I am including as source at compile time.

There is an mxmlLoadString(...) function which ends up calling calloc.
There is an mxmlDelete() function which ends up calling free.

If have a test which includes the Load only I get a memory leak for having allocated memory that was never freed. (seems reasonable).
If I include a delete on the pointer returned by Load, I get a memory leak failure for Deallocating non-allocated memory.

Terry's hint to 
CPPUTEST_USE_MEM_LEAK_DETECTION=N

works, but I don't think I actually want to turn memeory leak detection off, because finding where I called Load without delete is valuable.

Adding 
CXXFLAGS += -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorNewMacros.h 
CFLAGS += -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorMallocMacros.h

Had no impact.  

Right now I am assuming it is something I did and not somthing wrong in the open source library.  Any hints at what I should look at to understand the error message:

Memory leak reports about malloc and free can be caused by using the cpputest version of malloc, but deallocating with the standard free.
If this is the case, check whether your malloc/free replacements are working (#define malloc cpputest_malloc etc).

Thanks,

Mike

Mike Finch

unread,
Jan 6, 2014, 4:49:24 PM1/6/14
to cppu...@googlegroups.com
Forgot to add using CppUTest v3.3 created on 2012-08-24-09-41

Mike Finch

unread,
Jan 7, 2014, 8:58:23 AM1/7/14
to cppu...@googlegroups.com

Mike Finch

unread,
Jan 8, 2014, 8:14:55 AM1/8/14
to cppu...@googlegroups.com
I got some more help yesterday and determined that the reason I was getting an error for memory leak was that after the mxml library calloc'ed the memory, it took annother piece and did a strdup.  Then when freeing, the first thing it did was free the stringdup, which cppUNit did not recognize as an allocation.
I am going to attempt to make a wrapper for strdup this week.
 
Mike

Bas Vodde

unread,
Jan 12, 2014, 2:17:18 AM1/12/14
to cppu...@googlegroups.com

Hi Mike,

Sorry for not replying you earlier.

Related to strdup, int he MemoryLeakDetectorMallocMacros.h, there is the following comment:


/* NOTE on strdup!
*
* strdup was implemented earlier, however it is *not* an Standard C function but a POSIX function.
* Because of that, it can lead to portability issues by providing more than is available on the local platform.
* For that reason, strdup is *not* implemented as a macro. If you still want to use it, an easy implementation would be:
*
* size_t length = 1 + strlen(str);
* char* result = (char*) cpputest_malloc_location(length, file, line);
* memcpy(result, str, length);
* return result;
*
*/

Does that comment help you?

Thanks!

Bas
> --
> You received this message because you are subscribed to the Google Groups "cpputest" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to cpputest+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Mike Finch

unread,
Jan 21, 2014, 12:34:18 PM1/21/14
to cppu...@googlegroups.com
Thanks,
   This is working.


You received this message because you are subscribed to a topic in the Google Groups "cpputest" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cpputest/Ze9RjaKRm88/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cpputest+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages