PostGIS  3.4.0dev-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 304 of file lwgeom_geos_prepared.c.

305 {
306  PrepGeomHashEntry* pghe = 0;
307  PrepGeomCache* prepcache = (PrepGeomCache*)cache;
308 
309  if ( ! prepcache )
310  return LW_FAILURE;
311 
312  /*
313  * Clear out the references to the soon-to-be-freed GEOS objects
314  * from the callback hash entry
315  */
316  pghe = GetPrepGeomHashEntry(prepcache->context_callback);
317  if ( ! pghe )
318  {
319  lwpgerror("PrepGeomCacheCleaner failed to find hash entry for context %p", prepcache->context_callback);
320  return LW_FAILURE;
321  }
322  pghe->geom = 0;
323  pghe->prepared_geom = 0;
324 
325  /*
326  * Free the GEOS objects and free the index tree
327  */
328  POSTGIS_DEBUGF(3, "PrepGeomCacheFreeer: freeing %p argnum %d", prepcache, prepcache->gcache.argnum);
329  GEOSPreparedGeom_destroy( prepcache->prepared_geom );
330  GEOSGeom_destroy( (GEOSGeometry *)prepcache->geom );
331  prepcache->gcache.argnum = 0;
332  prepcache->prepared_geom = 0;
333  prepcache->geom = 0;
334 
335  return LW_SUCCESS;
336 }
#define LW_FAILURE
Definition: liblwgeom.h:96
#define LW_SUCCESS
Definition: liblwgeom.h:97
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: