PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ 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 397 of file lwgeom_geos_prepared.c.

398 {
399  PrepGeomHashEntry* pghe = 0;
400  PrepGeomCache* prepcache = (PrepGeomCache*)cache;
401 
402  if ( ! prepcache )
403  return LW_FAILURE;
404 
405  /*
406  * Clear out the references to the soon-to-be-freed GEOS objects
407  * from the callback hash entry
408  */
409  pghe = GetPrepGeomHashEntry(prepcache->context_callback);
410  if ( ! pghe )
411  {
412  lwpgerror("PrepGeomCacheCleaner failed to find hash entry for context %p", prepcache->context_callback);
413  return LW_FAILURE;
414  }
415  pghe->geom = 0;
416  pghe->prepared_geom = 0;
417 
418  /*
419  * Free the GEOS objects and free the index tree
420  */
421  POSTGIS_DEBUGF(3, "PrepGeomCacheFreeer: freeing %p argnum %d", prepcache, prepcache->gcache.argnum);
422  GEOSPreparedGeom_destroy( prepcache->prepared_geom );
423  GEOSGeom_destroy( (GEOSGeometry *)prepcache->geom );
424  prepcache->gcache.argnum = 0;
425  prepcache->prepared_geom = 0;
426  prepcache->geom = 0;
427 
428  return LW_SUCCESS;
429 }
#define LW_FAILURE
Definition: liblwgeom.h:79
#define LW_SUCCESS
Definition: liblwgeom.h:80
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: