[#22045] Memory leak in Mathutils.Matrix

own fault when adding mathutils callbacks, generic destructor didnt free the matrix accessor array, made the array apart of the matrix struct since its not worth malloc'ing to save at most 16bytes.
This commit is contained in:
2010-04-16 08:17:13 +00:00
parent 0028aa24c1
commit 182587fce1
7 changed files with 26 additions and 75 deletions

View File

@@ -118,7 +118,7 @@ static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
float scalar;
argSize = PyTuple_GET_SIZE(args);
if(argSize > 4){ //bad arg nums
if(argSize > MATRIX_MAX_DIM) { //bad arg nums
PyErr_SetString(PyExc_AttributeError, "mathutils.Matrix(): expects 0-4 numeric sequences of the same size\n");
return NULL;
} else if (argSize == 0) { //return empty 4D matrix
@@ -321,11 +321,6 @@ PyObject *Matrix_Resize4x4(MatrixObject * self)
PyErr_SetString(PyExc_MemoryError, "matrix.resize4x4(): problem allocating pointer space");
return NULL;
}
self->matrix = PyMem_Realloc(self->matrix, (sizeof(float *) * 4));
if(self->matrix == NULL) {
PyErr_SetString(PyExc_MemoryError, "matrix.resize4x4(): problem allocating pointer space");
return NULL;
}
/*set row pointers*/
for(x = 0; x < 4; x++) {
self->matrix[x] = self->contigPtr + (x * 4);
@@ -1425,12 +1420,6 @@ PyObject *newMatrixObject(float *mat, int rowSize, int colSize, int type, PyType
if(type == Py_WRAP){
self->contigPtr = mat;
/*create pointer array*/
self->matrix = PyMem_Malloc(rowSize * sizeof(float *));
if(self->matrix == NULL) { /*allocation failure*/
PyErr_SetString( PyExc_MemoryError, "matrix(): problem allocating pointer space");
return NULL;
}
/*pointer array points to contigous memory*/
for(x = 0; x < rowSize; x++) {
self->matrix[x] = self->contigPtr + (x * colSize);
@@ -1442,13 +1431,6 @@ PyObject *newMatrixObject(float *mat, int rowSize, int colSize, int type, PyType
PyErr_SetString( PyExc_MemoryError, "matrix(): problem allocating pointer space\n");
return NULL;
}
/*create pointer array*/
self->matrix = PyMem_Malloc(rowSize * sizeof(float *));
if(self->matrix == NULL) { /*allocation failure*/
PyMem_Free(self->contigPtr);
PyErr_SetString( PyExc_MemoryError, "matrix(): problem allocating pointer space");
return NULL;
}
/*pointer array points to contigous memory*/
for(x = 0; x < rowSize; x++) {
self->matrix[x] = self->contigPtr + (x * colSize);