Fix leaks in mathutils PySequence_Fast usage

This commit is contained in:
2015-07-29 09:49:02 +10:00
parent 376e4c945e
commit 96f08bf9a8
2 changed files with 4 additions and 2 deletions

View File

@@ -70,12 +70,10 @@ static int mathutils_array_parse_fast(float *array,
"%.200s: sequence index %d expected a number, " "%.200s: sequence index %d expected a number, "
"found '%.200s' type, ", "found '%.200s' type, ",
error_prefix, i, Py_TYPE(item)->tp_name); error_prefix, i, Py_TYPE(item)->tp_name);
Py_DECREF(value_fast);
return -1; return -1;
} }
} while (i); } while (i);
Py_XDECREF(value_fast);
return size; return size;
} }
@@ -182,6 +180,7 @@ int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *
} }
size = mathutils_array_parse_fast(array, size, value_fast, error_prefix); size = mathutils_array_parse_fast(array, size, value_fast, error_prefix);
Py_DECREF(value_fast);
} }
if (size != -1) { if (size != -1) {
@@ -239,6 +238,7 @@ int mathutils_array_parse_alloc(float **array, int array_min, PyObject *value, c
size = PySequence_Fast_GET_SIZE(value_fast); size = PySequence_Fast_GET_SIZE(value_fast);
if (size < array_min) { if (size < array_min) {
Py_DECREF(value_fast);
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"%.200s: sequence size is %d, expected > %d", "%.200s: sequence size is %d, expected > %d",
error_prefix, size, array_min); error_prefix, size, array_min);
@@ -248,6 +248,7 @@ int mathutils_array_parse_alloc(float **array, int array_min, PyObject *value, c
*array = PyMem_Malloc(size * sizeof(float)); *array = PyMem_Malloc(size * sizeof(float));
ret = mathutils_array_parse_fast(*array, size, value_fast, error_prefix); ret = mathutils_array_parse_fast(*array, size, value_fast, error_prefix);
Py_DECREF(value_fast);
if (ret == -1) { if (ret == -1) {
PyMem_Free(*array); PyMem_Free(*array);

View File

@@ -2226,6 +2226,7 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
if (mathutils_array_parse(vec, self->num_col, self->num_col, item, if (mathutils_array_parse(vec, self->num_col, self->num_col, item,
"matrix[begin:end] = value assignment") == -1) "matrix[begin:end] = value assignment") == -1)
{ {
Py_DECREF(value_fast);
return -1; return -1;
} }