Disable memory leak detection in one place?

239 views
Skip to first unread message

cp engr

unread,
Jan 9, 2015, 7:17:22 PM1/9/15
to cppu...@googlegroups.com
Hi,

We’re migrating from Visual Studio 2010 to 2013, so I need to move my unit tests to that platform. I’m getting a test failure on 2013 that I didn’t get on 2010. I see why it’s happening, but I don’t see why the platform migration should make any difference.

The test failure I’m getting is a memory leak detection. This is because there is purposely one place where we malloc() once, and never free(). The memory remains allocated for the life of the program. (There is a static bool that is used to ensure that the malloc() only ever gets called once.) Since it’s a C program, there’s no destructor to put the call to free() in…and it wouldn’t make sense for the embedded application, anyway.

I’d like to keep the memory leak detection on, but just disable it in this once instance. Is that possible?

Thanks,

cpengr

Steven Collins

unread,
Jan 9, 2015, 8:49:51 PM1/9/15
to cppu...@googlegroups.com
Why do an allocation at all? Why not just declare a static instance of the type and size you are allocating?


--
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/d/optout.

cp engr

unread,
Jan 9, 2015, 11:28:10 PM1/9/15
to cppu...@googlegroups.com
Because we haven't yet done the work to enable tags to statically allocate external memory on the embedded platform. Currently that's where the heap is, so we're relying on the side effect that malloc'ed things go there.

Bas Vodde

unread,
Jan 10, 2015, 1:44:08 AM1/10/15
to cppu...@googlegroups.com

Hi,

If you must keep the static bool, then the easiest is to call the method in the main before the test run.

That way, the malloc allocation is done before the memory leak detector starts recording and it won’t be reported as leak.

Hope this helps!

Thanks,

Bas

cp engr

unread,
Jan 12, 2015, 11:43:16 AM1/12/15
to cppu...@googlegroups.com
Good enough. Thanks.
Reply all
Reply to author
Forward
0 new messages