[Liblas-commits] r972 - trunk/python/liblas

liblas-commits at liblas.org liblas-commits at liblas.org
Thu Dec 25 22:59:28 EST 2008


Author: hobu
Date: Thu Dec 25 22:59:28 2008
New Revision: 972
URL: http://liblas.org/changeset/972

Log:
make sure to free heap allocated strings that were given to us by the C API

Modified:
   trunk/python/liblas/core.py

Modified: trunk/python/liblas/core.py
==============================================================================
--- trunk/python/liblas/core.py	(original)
+++ trunk/python/liblas/core.py	Thu Dec 25 22:59:28 2008
@@ -95,6 +95,16 @@
     free(result)
     return retval
 
+def free_returned_char_p(result, func, cargs):
+
+    size = ctypes.c_int()
+    print result, type(result), dir(result)
+    retvalue = ctypes.string_at(result, size.value)[:]
+    free(result)
+    return retvalue
+    
+    
+
 try:
     from numpy import array, ndarray
     HAS_NUMPY = True
@@ -137,13 +147,17 @@
     return las.LAS_GetVersion()
 
 
-las.LAS_GetVersion.restype = ctypes.c_char_p
+las.LAS_GetVersion.restype = ctypes.POINTER(ctypes.c_char)
+las.LAS_GetVersion.errcheck = free_returned_char_p
+
 version = get_version()
 las.LASError_GetLastErrorNum.restype = ctypes.c_int
 
-las.LASError_GetLastErrorMsg.restype = ctypes.c_char_p
+las.LASError_GetLastErrorMsg.restype = ctypes.POINTER(ctypes.c_char)
+las.LASError_GetLastErrorMsg.errcheck = free_returned_char_p
 
-las.LASError_GetLastErrorMethod.restype = ctypes.c_char_p
+las.LASError_GetLastErrorMethod.restype = ctypes.POINTER(ctypes.c_char)
+las.LASError_GetLastErrorMethod.errcheck = free_returned_char_p
 
 las.LASError_GetErrorCount.restype=ctypes.c_int
 


More information about the Liblas-commits mailing list