PostGIS  2.4.9dev-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 401 of file lwgeom_geos_prepared.c.

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

402 {
403  PrepGeomHashEntry* pghe = 0;
404  PrepGeomCache* prepcache = (PrepGeomCache*)cache;
405 
406  if ( ! prepcache )
407  return LW_FAILURE;
408 
409  /*
410  * Clear out the references to the soon-to-be-freed GEOS objects
411  * from the callback hash entry
412  */
413  pghe = GetPrepGeomHashEntry(prepcache->context_callback);
414  if ( ! pghe )
415  {
416  lwpgerror("PrepGeomCacheCleaner failed to find hash entry for context %p", prepcache->context_callback);
417  return LW_FAILURE;
418  }
419  pghe->geom = 0;
420  pghe->prepared_geom = 0;
421 
422  /*
423  * Free the GEOS objects and free the index tree
424  */
425  POSTGIS_DEBUGF(3, "PrepGeomCacheFreeer: freeing %p argnum %d", prepcache, prepcache->argnum);
426  GEOSPreparedGeom_destroy( prepcache->prepared_geom );
427  GEOSGeom_destroy( (GEOSGeometry *)prepcache->geom );
428  prepcache->argnum = 0;
429  prepcache->prepared_geom = 0;
430  prepcache->geom = 0;
431 
432  return LW_SUCCESS;
433 }
const GEOSPreparedGeometry * prepared_geom
#define LW_SUCCESS
Definition: liblwgeom.h:80
#define LW_FAILURE
Definition: liblwgeom.h:79
const GEOSPreparedGeometry * prepared_geom
const GEOSGeometry * geom
const GEOSGeometry * geom
static PrepGeomHashEntry * GetPrepGeomHashEntry(MemoryContext mcxt)
MemoryContext context_callback
Here is the call graph for this function: