From: Raphael N. <rn...@we...> - 2012-12-29 06:37:36
|
Hi, > I'm not sure and I haven't checked either, but I guess that you get > dangling pointers if they are freed. Maybe this only was true at some time > in the past, maybe it still is. I guess if you look at the freeAsmop > history you'll find a version that had free removed. Perhaps the memory > can be freed now, it's worth a try. We had a discussion on memory leaks discovered by Valgrind several months ago. Basically, sdcc is a short running program, which is supposed to handle rather small input files and convert them into equally rather short output. We thus simply do not care to release all allocated memory for two reasons: * performance (releasing thousands of objects can and does take considerable time; letting the OS simply cleanup the whole virtual memory associated with the program at its exit is much faster) * safety (as Maarten pointed out, dangling pointers could result in premature program termination; I am aware of the fact that this also covers programming errors, but still the current approach seems to work pretty well). I would recommend against changing such a crucial point just for the sake of code cleanliness. One might add a comment to indicate where free() should be placed and why it is not. Raphael >> While working on the stm8 port, I noticed that the other ports >> >> * Allcoate memory in newAsmop using Safe_calloc() or traceAlloc(). >> * Do not free this memory in freeAsmop(). >> >> This looks like a serious memory leak to me, but since all ports do it >> it probably isn't. What am I missing here? >> >> Philipp |