From fc4784a482c83f68f13abe4a54051da25348c005 Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Wed, 11 Apr 2012 12:22:34 -0600 Subject: BUG: Fix segfault when tests are run with python 2.7 debug. I don't know that the crash is python2.7 specific, it may also occur in earlier versions of python. The cause was mismatched memory allocation/deallocation of maskna data. --- numpy/core/src/multiarray/na_mask.c | 2 +- numpy/core/tests/test_regression.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'numpy') diff --git a/numpy/core/src/multiarray/na_mask.c b/numpy/core/src/multiarray/na_mask.c index 0e0e285b6..8fbe8ea60 100644 --- a/numpy/core/src/multiarray/na_mask.c +++ b/numpy/core/src/multiarray/na_mask.c @@ -361,7 +361,7 @@ PyArray_AllocateMaskNA(PyArrayObject *arr, } /* Allocate the mask memory */ - maskna_data = PyArray_malloc(size * maskna_dtype->elsize); + maskna_data = PyDataMem_NEW(size * maskna_dtype->elsize); if (maskna_data == NULL) { Py_DECREF(maskna_dtype); PyErr_NoMemory(); diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index ac36aa479..7905d38cd 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -1692,5 +1692,10 @@ class TestRegression(TestCase): a = np.array(['abc'], dtype=np.unicode)[0] del a + def test_maskna_deallocation(self): + # This caused a segfault when running under python-debug + a = np.array([1]).view(maskna=True) + del a + if __name__ == "__main__": run_module_suite() -- cgit v1.2.1