Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-04-16 12:17:13 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-04-16 12:17:13 +0400
commit182587fce100df0c9543e8be9493e9f539a3fbae (patch)
treeb7c0d36cca6460b208903b6db7c132b20c50ce5b
parent0028aa24c1f4195fbe01a7ba1db5c7841b6c4b49 (diff)
[#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.
-rw-r--r--source/blender/python/generic/mathutils.h27
-rw-r--r--source/blender/python/generic/mathutils_color.h9
-rw-r--r--source/blender/python/generic/mathutils_euler.h9
-rw-r--r--source/blender/python/generic/mathutils_matrix.c20
-rw-r--r--source/blender/python/generic/mathutils_matrix.h15
-rw-r--r--source/blender/python/generic/mathutils_quat.h11
-rw-r--r--source/blender/python/generic/mathutils_vector.h10
7 files changed, 26 insertions, 75 deletions
diff --git a/source/blender/python/generic/mathutils.h b/source/blender/python/generic/mathutils.h
index 0e87f49e30c..f5bbcfcf666 100644
--- a/source/blender/python/generic/mathutils.h
+++ b/source/blender/python/generic/mathutils.h
@@ -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);
diff --git a/source/blender/python/generic/mathutils_color.h b/source/blender/python/generic/mathutils_color.h
index f552dc99ee9..5e5800c9448 100644
--- a/source/blender/python/generic/mathutils_color.h
+++ b/source/blender/python/generic/mathutils_color.h
@@ -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
diff --git a/source/blender/python/generic/mathutils_euler.h b/source/blender/python/generic/mathutils_euler.h
index 994a5f1780e..1f63ddecd81 100644
--- a/source/blender/python/generic/mathutils_euler.h
+++ b/source/blender/python/generic/mathutils_euler.h
@@ -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;
diff --git a/source/blender/python/generic/mathutils_matrix.c b/source/blender/python/generic/mathutils_matrix.c
index 0c363df8837..0ce5641b07c 100644
--- a/source/blender/python/generic/mathutils_matrix.c
+++ b/source/blender/python/generic/mathutils_matrix.c
@@ -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);
diff --git a/source/blender/python/generic/mathutils_matrix.h b/source/blender/python/generic/mathutils_matrix.h
index 421cde6c20d..cb2876dce32 100644
--- a/source/blender/python/generic/mathutils_matrix.h
+++ b/source/blender/python/generic/mathutils_matrix.h
@@ -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
diff --git a/source/blender/python/generic/mathutils_quat.h b/source/blender/python/generic/mathutils_quat.h
index 0416bbe6042..151c8c8d2c7 100644
--- a/source/blender/python/generic/mathutils_quat.h
+++ b/source/blender/python/generic/mathutils_quat.h
@@ -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
diff --git a/source/blender/python/generic/mathutils_vector.h b/source/blender/python/generic/mathutils_vector.h
index cdb2a1e5f04..0efeca491c0 100644
--- a/source/blender/python/generic/mathutils_vector.h
+++ b/source/blender/python/generic/mathutils_vector.h
@@ -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;