diff --git a/django/contrib/gis/gdal/prototypes/generation.py b/django/contrib/gis/gdal/prototypes/generation.py index bba715d67c..1303532372 100644 --- a/django/contrib/gis/gdal/prototypes/generation.py +++ b/django/contrib/gis/gdal/prototypes/generation.py @@ -8,6 +8,9 @@ from django.contrib.gis.gdal.prototypes.errcheck import \ check_arg_errcode, check_errcode, check_geom, check_geom_offset, \ check_pointer, check_srs, check_str_arg, check_string, check_const_string +class gdal_char_p(c_char_p): + pass + def double_output(func, argtypes, errcheck=False, strarg=False): "Generates a ctypes function that returns a double value." func.argtypes = argtypes @@ -77,9 +80,9 @@ def string_output(func, argtypes, offset=-1, str_result=False): """ func.argtypes = argtypes if str_result: - # String is the result, don't explicitly define - # the argument type so we can get the pointer. - pass + # Use subclass of c_char_p so the error checking routine + # can free the memory at the pointer's address. + func.restype = gdal_char_p else: # Error code is returned func.restype = c_int diff --git a/django/contrib/gis/geos/prototypes/topology.py b/django/contrib/gis/geos/prototypes/topology.py index 633340901b..65c26f9f37 100644 --- a/django/contrib/gis/geos/prototypes/topology.py +++ b/django/contrib/gis/geos/prototypes/topology.py @@ -10,6 +10,7 @@ __all__ = ['geos_boundary', 'geos_buffer', 'geos_centroid', 'geos_convexhull', from ctypes import c_char_p, c_double, c_int from django.contrib.gis.geos.libgeos import lgeos, GEOM_PTR, GEOS_PREPARE from django.contrib.gis.geos.prototypes.errcheck import check_geom, check_string +from django.contrib.gis.geos.prototypes.geom import geos_char_p def topology(func, *args): "For GEOS unary topology functions." @@ -38,6 +39,7 @@ geos_union = topology(lgeos.GEOSUnion, GEOM_PTR) # GEOSRelate returns a string, not a geometry. geos_relate = lgeos.GEOSRelate geos_relate.argtypes = [GEOM_PTR, GEOM_PTR] +geos_relate.restype = geos_char_p geos_relate.errcheck = check_string # Routines only in GEOS 3.1+