[geos-devel] An Immodest Proposal

Martin Davis mbdavis at refractions.net
Wed Oct 1 17:59:23 EDT 2008


The geomFactory is static for the lifetime of GEOS, right?  So why is it 
freed at all between queries - shouldn't it live until the process 
containing GEOS ends (at which point the entire process image 
disappears, so it doesn't matter if it's never freed).

If the problem is that you are trying to delete this statically 
allocated object, then you need to find a way of *not* deleting that 
object.  Perhaps check the value of the pointer you are about to delete 
against this object and don't delete it if is the same?

Paul Ramsey wrote:
> So, moving the instantiation of geomFactory object into initGEOS did
> nothing for me, the object is still allocated by malloc, not palloc,
> perhaps because it's a global, so it's getting set up at library load
> time?
>
> Putting the whole factory and creation process inside the function
> bodies could get very expensive, since the functions are called
> repetitively a lot, which means each call would do a newfactory,
> newgeo, destroygeom, destroyfactory (ack!).  This is presumably why
> the factory was made into a global outside the functions.
>
> I'm at an impasse. If new/delete are overridden, when the end of a
> postgres comes along, the system will attempt to pfree the globals as
> it cleans up the library, and since the globals are malloc'ed,
> segfault ensues.
>
> If we backtrack to not over-riding new/delete, then we have the
> problem of leaking the prepared objects at the end of each
> transaction.
>
> P.
>
> On Wed, Oct 1, 2008 at 11:08 AM, Paul Ramsey <pramsey at cleverelephant.ca> wrote:
>   
>> So, using a longer lived memory context I can get right to the end of
>> a query before the segfault arrives. The segfault happens when
>> deleting a geometryfactory at the end, which tells me a couple things,
>> I think.
>>
>> First, those two std allocs that sneak in before we over-ride new are
>> related to the geometry factory. The segfault happens when we're
>> trying to pfree the geometryfactory.
>>
>> The offending code is this in geos_c.cpp:
>>
>> // NOTE: SRID will have to be changed after geometry creation
>> static const GeometryFactory *geomFactory =
>>        GeometryFactory::getDefaultInstance();
>>
>> This global geomFactory is called a number of times by WKB readers and
>> some other functions.  I wonder if we can initialize it in initGEOS
>> and clean it up in finishGEOS?
>>
>> It appears, that this is what used to happen? Here's the current code.
>>
>> void
>> finishGEOS ()
>> {
>>        // Nothing to do
>>        //delete geomFactory;
>> }
>>
>> Any help on the history behind this global?
>>
>> P.
>>
>>     
> _______________________________________________
> geos-devel mailing list
> geos-devel at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/geos-devel
>
>   

-- 
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022



More information about the geos-devel mailing list