summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Heller <theller@ctypes.org>2006-05-05 18:43:24 +0000
committerThomas Heller <theller@ctypes.org>2006-05-05 18:43:24 +0000
commit748f6fbf2cbd0408ef3cdbe1661acaa5d72bee21 (patch)
treef9f8c9c3af25d91e1cec33dae0715ac5ac4874ac
parent21a929f5ab6dd52b880e49272a50de5ee507137d (diff)
downloadcpython-git-748f6fbf2cbd0408ef3cdbe1661acaa5d72bee21.tar.gz
Fix memory leaks in the ctypes test suite, reported by valgrind, by
free()ing the memory we allocate.
-rw-r--r--Lib/ctypes/test/test_slicing.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/ctypes/test/test_slicing.py b/Lib/ctypes/test/test_slicing.py
index 44d0b11664..008e92fc26 100644
--- a/Lib/ctypes/test/test_slicing.py
+++ b/Lib/ctypes/test/test_slicing.py
@@ -39,16 +39,19 @@ class SlicesTestCase(unittest.TestCase):
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 @@ class SlicesTestCase(unittest.TestCase):
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 @@ class SlicesTestCase(unittest.TestCase):
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)
################################################################