[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43834] trunk/blender/source/blender/ python/mathutils/mathutils_Vector.c: Fix for possible memory leak on creation of a vector using Vector.Range.
Andrew Hale
TrumanBlending at gmail.com
Thu Feb 2 02:07:11 CET 2012
Revision: 43834
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43834
Author: trumanblending
Date: 2012-02-02 01:07:04 +0000 (Thu, 02 Feb 2012)
Log Message:
-----------
Fix for possible memory leak on creation of a vector using Vector.Range.
It was possible to allocate an array of size<2 which would then raise an error on vector creation without freeing.
Fix to ensure the behaviour of Vector.Range was the same as for builtin range() function. When specifying 3 arguments, the step argument wasn't being used to correctly calculate the vector size.
Minor formatting edits for error messages.
Modified Paths:
--------------
trunk/blender/source/blender/python/mathutils/mathutils_Vector.c
Modified: trunk/blender/source/blender/python/mathutils/mathutils_Vector.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_Vector.c 2012-02-02 00:14:35 UTC (rev 43833)
+++ trunk/blender/source/blender/python/mathutils/mathutils_Vector.c 2012-02-02 01:07:04 UTC (rev 43834)
@@ -174,7 +174,7 @@
case 2:
if (start >= stop) {
PyErr_SetString(PyExc_RuntimeError,
- "Start value is larger"
+ "Start value is larger "
"than the stop value");
return NULL;
}
@@ -184,16 +184,27 @@
default:
if (start >= stop) {
PyErr_SetString(PyExc_RuntimeError,
- "Start value is larger"
+ "Start value is larger "
"than the stop value");
return NULL;
}
- size = (stop - start)/step;
- if (size%step)
- size++;
+
+ size = (stop - start);
+
+ if ((size % step) != 0)
+ size += step;
+
+ size /= step;
+
break;
}
+ if (size < 2) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Vector(): invalid size");
+ return NULL;
+ }
+
vec = PyMem_Malloc(size * sizeof(float));
if (vec == NULL) {
More information about the Bf-blender-cvs
mailing list