Does the memory leak check not work?

25 views
Skip to first unread message

Nic McPhee

unread,
Sep 7, 2009, 8:57:05 PM9/7/09
to Cmockery
I'm new to Cmockery, and it's likely to prove very useful for me. I
was disappointed, though, to find that apparently the memory leak
check doesn't work. When I comment out all the free calls in the code
I'm testing, all the tests still pass, and when I run the
allocate_module example with just the memory leak test it also passes.

Is this a known problem? Do I need to do something to enable that
functionality?

Many thanks in advance,

Nic

Alexander Demin

unread,
Sep 8, 2009, 5:26:15 AM9/8/09
to cmoc...@googlegroups.com
Nic,

Can you show the source of your example?

Regards,
Alexander

Nic McPhee

unread,
Sep 8, 2009, 9:31:37 AM9/8/09
to Cmockery
I downloaded the files allocate_module.c and allocate_module_test.c
from the manual (http://cmockery.googlecode.com/svn/trunk/doc/
index.html#Dynamic_Memory_Allocation), and commented out the second
and third test in the main method of the test file:

int main(int argc, char* argv[]) {
const UnitTest tests[] = {
unit_test(leak_memory_test) // ,
/*
unit_test(buffer_overflow_test),
unit_test(buffer_underflow_test), */
};
return run_tests(tests);
}

My reading of the documentation indicates that this should fail, but
it passes quite happily.

Thoughts?

Nic

Stewart Miles

unread,
Sep 8, 2009, 12:25:02 PM9/8/09
to cmoc...@googlegroups.com
Running allocate_module.c on windows....

C:\src-cmockery\cmockery\windows>allocate_module_test.exe
leak_memory_test: Starting test
Blocks allocated...
0x00032c18 : ..\src\example\allocate_module.c:36
ERROR: leak_memory_test leaked 1 block(s)
leak_memory_test: Test failed.
buffer_overflow_test: Starting test
Guard block of 0x00032c50 size=4 allocated by
..\src\example\allocate_module.c:41 at 0x00032c54 is corrupt
ERROR: ..\src\example\allocate_module.c:43 Failure!
buffer_overflow_test: Test failed.
buffer_underflow_test: Starting test
Guard block of 0x00032ca8 size=4 allocated by
..\src\example\allocate_module.c:47 at 0x00032ca7 is corrupt
ERROR: ..\src\example\allocate_module.c:49 Failure!
buffer_underflow_test: Test failed.
3 out of 3 tests failed!
leak_memory_test
buffer_overflow_test
buffer_underflow_test
Blocks allocated...
0x00032c18 : ..\src\example\allocate_module.c:41
0x00032c70 : ..\src\example\allocate_module.c:47
Guard block of 0x00032c50 size=4 allocated by
..\src\example\allocate_module.c:41 at 0x00032c54 is corrupt
ERROR: ..\src\cmockery.c:1463 Failure!


On Linux....

cmockery2$./allocate_module_test
leak_memory_test: Starting test
Blocks allocated...
0x00601150 : src/example/allocate_module.c:36
ERROR: leak_memory_test leaked 1 block(s)
leak_memory_test: Test failed.
buffer_overflow_test: Starting test
Guard block of 0x006011b0 size=4 allocated by
src/example/allocate_module.c:41 at 0x006011b4 is corrupt
ERROR: src/example/allocate_module.c:43 Failure!
buffer_overflow_test: Test failed.
buffer_underflow_test: Starting test
Guard block of 0x00601230 size=4 allocated by
src/example/allocate_module.c:47 at 0x0060122f is corrupt
ERROR: src/example/allocate_module.c:49 Failure!
buffer_underflow_test: Test failed.
3 out of 3 tests failed!
leak_memory_test
buffer_overflow_test
buffer_underflow_test
Blocks allocated...
0x00601150 : src/example/allocate_module.c:41
0x006011d0 : src/example/allocate_module.c:47
Guard block of 0x006011b0 size=4 allocated by
src/example/allocate_module.c:41 at 0x006011b4 is corrupt
ERROR: src/cmockery.c:1463 Failure!

The leak_memory_test fails in both my test cases. Could you give the
exact steps you're using to build cmockery, the platform and your test
output?

Thanks,
Stewart
Reply all
Reply to author
Forward
0 new messages