[Python-checkins] r45914 - python/trunk/Lib/ctypes/test/test_slicing.py

thomas.heller python-checkins at python.org
Fri May 5 20:43:24 CEST 2006


Author: thomas.heller
Date: Fri May  5 20:43:24 2006
New Revision: 45914

Modified:
   python/trunk/Lib/ctypes/test/test_slicing.py
Log:
Fix memory leaks in the ctypes test suite, reported by valgrind, by
free()ing the memory we allocate.


Modified: python/trunk/Lib/ctypes/test/test_slicing.py
==============================================================================
--- python/trunk/Lib/ctypes/test/test_slicing.py	(original)
+++ python/trunk/Lib/ctypes/test/test_slicing.py	Fri May  5 20:43:24 2006
@@ -39,16 +39,19 @@
 
         dll = CDLL(_ctypes_test.__file__)
         dll.my_strdup.restype = POINTER(c_char)
+        dll.my_free.restype = None
         res = dll.my_strdup(s)
         self.failUnlessEqual(res[:len(s)], s)
 
         import operator
         self.assertRaises(TypeError, operator.setslice,
                           res, 0, 5, u"abcde")
+        dll.free(res)
 
         dll.my_strdup.restype = POINTER(c_byte)
         res = dll.my_strdup(s)
         self.failUnlessEqual(res[:len(s)-1], range(ord("a"), ord("z")+1))
+        dll.free(res)
 
     def test_char_array(self):
         s = "abcdefghijklmnopqrstuvwxyz\0"
@@ -68,12 +71,14 @@
             dll = CDLL(_ctypes_test.__file__)
             dll.my_wcsdup.restype = POINTER(c_wchar)
             dll.my_wcsdup.argtypes = POINTER(c_wchar),
+            dll.my_free.restype = None
             res = dll.my_wcsdup(s)
             self.failUnlessEqual(res[:len(s)], s)
 
             import operator
             self.assertRaises(TypeError, operator.setslice,
                               res, 0, 5, u"abcde")
+            dll.free(res)
 
             if sizeof(c_wchar) == sizeof(c_short):
                 dll.my_wcsdup.restype = POINTER(c_short)
@@ -81,8 +86,11 @@
                 dll.my_wcsdup.restype = POINTER(c_int)
             elif sizeof(c_wchar) == sizeof(c_long):
                 dll.my_wcsdup.restype = POINTER(c_long)
+            else:
+                return
             res = dll.my_wcsdup(s)
             self.failUnlessEqual(res[:len(s)-1], range(ord("a"), ord("z")+1))
+            dll.free(res)
 
 ################################################################
 


More information about the Python-checkins mailing list