[#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:
@@ -33,26 +33,29 @@
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include "mathutils_vector.h"
|
||||
#include "mathutils_matrix.h"
|
||||
#include "mathutils_quat.h"
|
||||
#include "mathutils_euler.h"
|
||||
#include "mathutils_color.h"
|
||||
|
||||
/* Can cast different mathutils types to this, use for generic funcs */
|
||||
|
||||
extern char BaseMathObject_Wrapped_doc[];
|
||||
extern char BaseMathObject_Owner_doc[];
|
||||
|
||||
#define BASE_MATH_MEMBERS(_data) \
|
||||
PyObject_VAR_HEAD \
|
||||
float *_data; /* array of data (alias), wrapped status depends on wrapped status */ \
|
||||
PyObject *cb_user; /* if this vector references another object, otherwise NULL, *Note* this owns its reference */ \
|
||||
unsigned char cb_type; /* which user funcs do we adhere to, RNA, GameObject, etc */ \
|
||||
unsigned char cb_subtype; /* subtype: location, rotation... to avoid defining many new functions for every attribute of the same type */ \
|
||||
unsigned char wrapped; /* wrapped data type? */ \
|
||||
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD
|
||||
float *data; /*array of data (alias), wrapped status depends on wrapped status */
|
||||
PyObject *cb_user; /* if this vector references another object, otherwise NULL, *Note* this owns its reference */
|
||||
unsigned char cb_type; /* which user funcs do we adhere to, RNA, GameObject, etc */
|
||||
unsigned char cb_subtype; /* subtype: location, rotation... to avoid defining many new functions for every attribute of the same type */
|
||||
unsigned char wrapped; /* wrapped data type? */
|
||||
BASE_MATH_MEMBERS(data)
|
||||
} BaseMathObject;
|
||||
|
||||
#include "mathutils_vector.h"
|
||||
#include "mathutils_matrix.h"
|
||||
#include "mathutils_quat.h"
|
||||
#include "mathutils_euler.h"
|
||||
#include "mathutils_color.h"
|
||||
|
||||
PyObject *BaseMathObject_getOwner( BaseMathObject * self, void * );
|
||||
PyObject *BaseMathObject_getWrapped( BaseMathObject *self, void * );
|
||||
void BaseMathObject_dealloc(BaseMathObject * self);
|
||||
|
@@ -37,14 +37,7 @@ extern PyTypeObject color_Type;
|
||||
#define ColorObject_Check(_v) PyObject_TypeCheck((_v), &color_Type)
|
||||
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD
|
||||
float *col; /*1D array of data */
|
||||
PyObject *cb_user; /* if this vector references another object, otherwise NULL, *Note* this owns its reference */
|
||||
unsigned char cb_type; /* which user funcs do we adhere to, RNA, GameObject, etc */
|
||||
unsigned char cb_subtype; /* subtype: location, rotation... to avoid defining many new functions for every attribute of the same type */
|
||||
unsigned char wrapped; /* wrapped data type? */
|
||||
/* end BaseMathObject */
|
||||
|
||||
BASE_MATH_MEMBERS(col);
|
||||
} ColorObject;
|
||||
|
||||
/*struct data contains a pointer to the actual data that the
|
||||
|
@@ -37,14 +37,7 @@ extern PyTypeObject euler_Type;
|
||||
#define EulerObject_Check(_v) PyObject_TypeCheck((_v), &euler_Type)
|
||||
|
||||
typedef struct {
|
||||
PyObject_VAR_HEAD
|
||||
float *eul; /*1D array of data */
|
||||
PyObject *cb_user; /* if this vector references another object, otherwise NULL, *Note* this owns its reference */
|
||||
unsigned char cb_type; /* which user funcs do we adhere to, RNA, GameObject, etc */
|
||||
unsigned char cb_subtype; /* subtype: location, rotation... to avoid defining many new functions for every attribute of the same type */
|
||||
unsigned char wrapped; /* wrapped data type? */
|
||||
/* end BaseMathObject */
|
||||
|
||||
BASE_MATH_MEMBERS(eul);
|
||||
unsigned char order; /* rotation order */
|
||||
|
||||
} EulerObject;
|
||||
|
@@ -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);
|
||||
|
@@ -34,21 +34,14 @@
|
||||
|
||||
extern PyTypeObject matrix_Type;
|
||||
#define MatrixObject_Check(_v) PyObject_TypeCheck((_v), &matrix_Type)
|
||||
#define MATRIX_MAX_DIM 4
|
||||
|
||||
typedef float **ptRow;
|
||||
typedef struct _Matrix { /* keep aligned with BaseMathObject in mathutils.h */
|
||||
PyObject_VAR_HEAD
|
||||
float *contigPtr; /*1D array of data (alias)*/
|
||||
PyObject *cb_user; /* if this vector references another object, otherwise NULL, *Note* this owns its reference */
|
||||
unsigned char cb_type; /* which user funcs do we adhere to, RNA, GameObject, etc */
|
||||
unsigned char cb_subtype; /* subtype: location, rotation... to avoid defining many new functions for every attribute of the same type */
|
||||
unsigned char wrapped; /*is wrapped data?*/
|
||||
/* end BaseMathObject */
|
||||
typedef struct {
|
||||
BASE_MATH_MEMBERS(contigPtr);
|
||||
|
||||
unsigned char rowSize;
|
||||
unsigned int colSize;
|
||||
ptRow matrix; /*ptr to the contigPtr (accessor)*/
|
||||
|
||||
float *matrix[MATRIX_MAX_DIM]; /* ptr to the contigPtr (accessor) */
|
||||
} MatrixObject;
|
||||
|
||||
/*struct data contains a pointer to the actual data that the
|
||||
|
@@ -36,15 +36,8 @@
|
||||
extern PyTypeObject quaternion_Type;
|
||||
#define QuaternionObject_Check(_v) PyObject_TypeCheck((_v), &quaternion_Type)
|
||||
|
||||
typedef struct { /* keep aligned with BaseMathObject in mathutils.h */
|
||||
PyObject_VAR_HEAD
|
||||
float *quat; /* 1D array of data (alias) */
|
||||
PyObject *cb_user; /* if this vector references another object, otherwise NULL, *Note* this owns its reference */
|
||||
unsigned char cb_type; /* which user funcs do we adhere to, RNA, GameObject, etc */
|
||||
unsigned char cb_subtype; /* subtype: location, rotation... to avoid defining many new functions for every attribute of the same type */
|
||||
unsigned char wrapped; /* wrapped data type? */
|
||||
/* end BaseMathObject */
|
||||
|
||||
typedef struct {
|
||||
BASE_MATH_MEMBERS(quat);
|
||||
} QuaternionObject;
|
||||
|
||||
/*struct data contains a pointer to the actual data that the
|
||||
|
@@ -36,14 +36,8 @@
|
||||
extern PyTypeObject vector_Type;
|
||||
#define VectorObject_Check(_v) PyObject_TypeCheck((_v), &vector_Type)
|
||||
|
||||
typedef struct { /* keep aligned with BaseMathObject in mathutils.h */
|
||||
PyObject_VAR_HEAD
|
||||
float *vec; /*1D array of data (alias), wrapped status depends on wrapped status */
|
||||
PyObject *cb_user; /* if this vector references another object, otherwise NULL, *Note* this owns its reference */
|
||||
unsigned char cb_type; /* which user funcs do we adhere to, RNA, GameObject, etc */
|
||||
unsigned char cb_subtype; /* subtype: location, rotation... to avoid defining many new functions for every attribute of the same type */
|
||||
unsigned char wrapped; /* wrapped data type? */
|
||||
/* end BaseMathObject */
|
||||
typedef struct {
|
||||
BASE_MATH_MEMBERS(vec);
|
||||
|
||||
unsigned char size; /* vec size 2,3 or 4 */
|
||||
} VectorObject;
|
||||
|
Reference in New Issue
Block a user