[postgis-devel] Memory Leak (Two Senses)

Paul Ramsey pramsey at cleverelephant.ca
Tue Jan 6 22:35:21 PST 2009


We seem to be suffering from a couple of massive memory leaks in liblwgeom.

The first one. While debugging the GUI, I noticed that it leaks gobs,
nay torrents, of memory. One leak was in the old loader code, or
perhaps was added during the lwgeom renovation. The other one was
harder to see. Valgrind insisted that memory allocated when building
pointarrays was not being freed. But the code block in the loader was
air-tight. Mark cleaned everything up. So, I went into liblwgeom, and
there, past the lwfree_polygon that Mark called, was the
lwfree_pointarray, and Lo: it didn't both to free the actual array of
POINT underlying the whole thing. I fix that, the leak disappears.

The second memory leak. The lwfree_pointarray function is defined in
lwgeom_api, and it is directly below a comment block that says *this*:

/****************************************************************
 * memory management
 *
 *  these only delete the memory associated
 *  directly with the structure - NOT the stuff pointing into
 *  the original de-serialized info
 *
 ****************************************************************/

Oh! That seems pretty clear. So by changing the function to fully
clean up after itself, I'm contravening the documented intent.
However, grep tells me the function is but lightly used in the code
base, hardly at all, really.  Our second memory leak is historical, we
have no idea why the intent was once this way.

Before I commit the changes to the lwfree_* set to make them finally,
actually, do deep freeing, can anyone provide the historical context
around the rules I seem to want to break?

Paul



More information about the postgis-devel mailing list