PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ PrepGeomCacheCleaner()

static int PrepGeomCacheCleaner ( GeomCache *  cache)
static

This function is passed into the generic GetGeomCache function in the case of a cache miss, so that it can free the particular indexed structure being managed.

In the case of prepared geometry, we want to leave the actual PrepGeomCache allocated and in place, but ensure that the GEOS Geometry and PreparedGeometry are freed so we don't leak memory as we transition from cache hit to miss to hit, etc.

Definition at line 387 of file lwgeom_geos_prepared.c.

388{
389 PrepGeomHashEntry* pghe = 0;
390 PrepGeomCache* prepcache = (PrepGeomCache*)cache;
391
392 if ( ! prepcache )
393 return LW_FAILURE;
394
395 /*
396 * Clear out the references to the soon-to-be-freed GEOS objects
397 * from the callback hash entry
398 */
399 pghe = GetPrepGeomHashEntry(prepcache->context_callback);
400 if ( ! pghe )
401 {
402 lwpgerror("PrepGeomCacheCleaner failed to find hash entry for context %p", prepcache->context_callback);
403 return LW_FAILURE;
404 }
405 pghe->geom = 0;
406 pghe->prepared_geom = 0;
407
408 /*
409 * Free the GEOS objects and free the index tree
410 */
411 POSTGIS_DEBUGF(3, "PrepGeomCacheFreeer: freeing %p argnum %d", prepcache, prepcache->gcache.argnum);
412 GEOSPreparedGeom_destroy( prepcache->prepared_geom );
413 GEOSGeom_destroy( (GEOSGeometry *)prepcache->geom );
414 prepcache->gcache.argnum = 0;
415 prepcache->prepared_geom = 0;
416 prepcache->geom = 0;
417
418 return LW_SUCCESS;
419}
#define LW_FAILURE
Definition liblwgeom.h:110
#define LW_SUCCESS
Definition liblwgeom.h:111
static PrepGeomHashEntry * GetPrepGeomHashEntry(MemoryContext mcxt)
const GEOSPreparedGeometry * prepared_geom
const GEOSGeometry * geom
MemoryContext context_callback
const GEOSGeometry * geom
const GEOSPreparedGeometry * prepared_geom

References PrepGeomCache::context_callback, PrepGeomCache::gcache, PrepGeomHashEntry::geom, PrepGeomCache::geom, GetPrepGeomHashEntry(), LW_FAILURE, LW_SUCCESS, PrepGeomHashEntry::prepared_geom, and PrepGeomCache::prepared_geom.

Here is the call graph for this function: