Changeset 998

Show
Ignore:
Timestamp:
01/03/08 14:55:22
Author:
seang
Message:

Plug memory leak in BaseGeometry?.relate

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Shapely/trunk/shapely/geometry/base.py

    r944 r998  
    66import sys 
    77 
    8 from shapely.geos import lgeos 
     8from shapely.geos import lgeos, free, allocated_c_char_p 
    99from shapely.predicates import BinaryPredicate, UnaryPredicate 
    1010from shapely.topology import BinaryTopologicalOp, UnaryTopologicalOp 
     
    304304    def relate(self, other): 
    305305        func = lgeos.GEOSRelate 
    306         func.restype = c_char_p 
     306        def errcheck(result, func, argtuple): 
     307            retval = result.value 
     308            free(result) 
     309            return retval 
     310        func.restype = allocated_c_char_p 
     311        func.errcheck = errcheck 
    307312        return lgeos.GEOSRelate(self._geom, other._geom) 
    308313 
  • Shapely/trunk/shapely/geos.py

    r888 r998  
    44 
    55import atexit 
    6 from ctypes import CDLL, CFUNCTYPE, c_char_p 
     6from ctypes import cdll, CDLL, CFUNCTYPE, c_char_p 
    77from ctypes.util import find_library 
    88import sys 
     
    1717    except: 
    1818        raise 
     19    free = cdll.msvcrt.free 
    1920elif sys.platform == 'darwin': 
    2021    lgeos = CDLL(find_library('geos_c')) 
     22    free = CDLL(find_library('libc')).free 
    2123else: 
    2224    # Try the major versioned name first, falling back on the unversioned name. 
     
    2729    except: 
    2830        raise 
     31    free = CDLL('libc.so.6').free 
     32 
     33 
     34class allocated_c_char_p(c_char_p): 
     35    pass 
     36 
    2937 
    3038# Exceptions