Can Cpputest detect memory leak caused by file description not close?

197 views
Skip to first unread message

xiaohong liu

unread,
Sep 29, 2011, 4:57:10 AM9/29/11
to cppu...@googlegroups.com
Hi, All

I use Cpputest to do ut where the code has problem that one file description not closed after function calling. But Cpputest doesn't report it. CppUtest can detact memory leaks such as new/free error, which proving the memeory leak check functions is active.

Is there anything options I have to active?

thanks
Xiaohong Liu

Bas Vodde

unread,
Sep 29, 2011, 7:51:37 AM9/29/11
to cppu...@googlegroups.com

Hiya,

I'm slightly unclear about your question, but I'll try to answer it.

For memory leak detection, yes, CppUTest support new, new[] and malloc memory leak detection.

The new/new[] is on by default, though the leak information isn't enabled them. To do that, you have to compile your production code with an additional header. You can find what to do at:
http://cpputest.org/node/25

With this additional header, there is also malloc/free support. Though, it uses scary defines which sometimes trigger scary compilation errors :)

Does that help you further?

Thanks!

Bas

xiaohong liu

unread,
Sep 30, 2011, 3:21:09 AM9/30/11
to cppu...@googlegroups.com
No. My question is that if I open a file but not close the file handle at the end, cpputest has not report on such leak.

thanks
Xiaohong 

2011/9/29 Bas Vodde <ba...@odd-e.com>

Bas Vodde

unread,
Sep 30, 2011, 5:27:55 AM9/30/11
to cppu...@googlegroups.com

Hiya,

Ah, no. Though you can do it in a similar way :)

I think the biggest problem is that you need to replace the calls using pre-processor macros. One thing you can do is to new some memory in it and call the OS function. Something like:

#define fopen(filename, mode) my_leak_checking_fopen(filename, mode)

Then you need to implement my_leak_checking_fopen and you could allocate some memory. But you need to de-allocate it in the my_leak_checking_fclose then...

Anyways, it is not by default in CppUTest. Sorry!

Bas

Reply all
Reply to author
Forward
0 new messages