Freeing memory allocated by realloc() throw's error
Opened this issue · 1 comments
GoogleCodeExporter commented
What steps will reproduce the problem?
Below steps throw's Guard block error which I expect it shouldn't.
void leak_memory() {
int * temporary = (int*)realloc(NULL, sizeof(int));
temporary = (int *) realloc (temporary, (10 * sizeof (int)));
free (temporary);
}
What is the expected output? What do you see instead?
Expected :-
===========
Allocated memory by realloc function should be free'd and test case should
pass.
Output Seen:-
=======================================================================
leak_memory_test: Starting test
Guard block of 0x00501120 size=0 allocated by :5247040 at 0x00501118 is
corrupt
ERROR: src/example/allocate_module.c:33 Failure!
leak_memory_test: Test failed.
1 out of 1 tests failed!
leak_memory_test
=======================================================================
What version of the product are you using? On what operating system?
Product version -
=============
cmockery-0.1.2
Operating System -
====================
ukhml-bladeAS4-~/mywork/cmockery-0.1.2/src/example: uname -a
Linux ukhml-bladeAS4 2.6.9-89.0.11.ELsmp #1 SMP Mon Aug 31 11:00:34 EDT
2009 x86_64 x86_64 x86_64 GNU/Linux
ukhml-bladeAS4-~/mywork/cmockery-0.1.2/src/example:
====================
Please provide any additional information below.
In my actual unit test case, program flow calls these below functions in
sequence which result in guard block error -
step
1.) malloc
2.) realloc and
3.) free.
Only work around I could do was just replace all such calls to
corresponding calls of realloc function for initial request to memory, re-
sizing memory and for freeing memory which overcame this error.
I was not able to re-produce with this sequence in an independent program.
Instead a sequence of realloc and free helped in reproducing this error
message which I mentioned above.
Is it something that realloc is not monitored by comockery ?
Thanks & Regards.,
Naveen Sriram.
Original issue reported on code.google.com by naveen.sriram@gmail.com
on 22 Mar 2010 at 1:42
GoogleCodeExporter commented
After adding patch "cmockery-realloc-patch"
(http://groups.google.com/group/cmockery/files), above issue got fixed. Thanks
to
"Eduardo Feo" for providing this patch.
Original comment by naveen.sriram@gmail.com
on 24 Mar 2010 at 6:54