RE: [suse-programming-e] False memleak detected?
Verdi March wrote on Monday, June 19, 2006 12:55 PM::
Valgrind detected memleak on one of my test case, which is a standard, textbook insertion sort. However, I don't see any problem with the testcase. I'm wondering if this is a false alarm, and should submit a bug report.
The reason you're getting the report is because ilist is local to main(). After leaving main() which is where valgrind does its leakage tests, there is no longer a list, so there can be no references to the allocated nodes. If you make ilist global, valgrind is silent. Believe valgrind - it is wiser than mere humans! There IS a very real leak that your example doesn't reveal:
} else if (is->i == (*isp)->i) { /* return FALSE; */ return 0; }
If you try to insert a node that is already in the list, "is" is not linked into the list, and the caller (i.e. insert) has already relinquished control so has no way of releasing the node. You would be better off changing the code so that the calloc is only performed once you've identified the need to insert the node (i.e. after the for-loop in insertion_sort()) Phil -- ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the H.E Information Systems Ltd. Tel: 0161 866 9066 Web: www.heis.co.uk This footnote also confirms that this email message has been swept by MIMEsweeper for the presence of computer viruses. www.clearswift.com **********************************************************************
Hi, On Tuesday 20 June 2006 01:03, Phil Betts wrote:
There IS a very real leak that your example doesn't reveal:
} else if (is->i == (*isp)->i) { /* return FALSE; */ return 0; }
If you try to insert a node that is already in the list, "is" is not linked into the list, and the caller (i.e. insert) has already relinquished control so has no way of releasing the node.
Yes, I was aware of that, it occur in one of my programs that uses the above code. Of course, detected by valgrind and fixed right away. -- Regards, Verdi
participants (2)
-
Phil Betts
-
Verdi March