From 816ed68db5203bf2e891681739d563bbd98d267b Mon Sep 17 00:00:00 2001 From: Willian Padovani Germano Date: Tue, 27 Jun 2006 17:51:11 +0000 Subject: [PATCH] BPython: Bug #4484: http://projects.blender.org/tracker/?func=detail&aid=4484&group_id=9&atid=125 A recent update to Draw.c made the button attr setter function not exit where it should for one of the cases, when new and old strings had same length (code was missing a "return 0;" line in one of the if cases). Should work fine now, I don't get the error under linux anymore. Also saw in the same function that a py object could be created but was not being decref'ed in two other 'if' cases. Thanks elbarto for reporting the bug. --- source/blender/python/api2_2x/Draw.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/source/blender/python/api2_2x/Draw.c b/source/blender/python/api2_2x/Draw.c index ad26235a477..d2a1331d4eb 100644 --- a/source/blender/python/api2_2x/Draw.c +++ b/source/blender/python/api2_2x/Draw.c @@ -406,6 +406,7 @@ static int Button_setattr( PyObject * self, char *name, PyObject * v ) PyObject *pyVal = PyNumber_Int( v ); if (pyVal) { but->val.asint = (int)PyInt_AS_LONG( pyVal ); + Py_DECREF(pyVal); return 0; } } @@ -413,6 +414,7 @@ static int Button_setattr( PyObject * self, char *name, PyObject * v ) PyObject *pyVal = PyNumber_Float( v ); if (pyVal) { but->val.asfloat = (float)PyFloat_AS_DOUBLE( pyVal ); + Py_DECREF(pyVal); return 0; } } @@ -427,13 +429,16 @@ static int Button_setattr( PyObject * self, char *name, PyObject * v ) PyString_AsStringAndSize( v, &newstr, &newlen ); if (newlen+1> UI_MAX_DRAW_STR) - return EXPP_ReturnIntError( PyExc_ValueError, "Error, the string assigned to this button has a length greator then 399"); - + return EXPP_ReturnIntError( PyExc_ValueError, "Error: button string length exceeded max limit (399 chars)."); + /* if the length of the new string is the same as */ /* the old one, just copy, else delete and realloc. */ if( but->slen == newlen ) { BLI_strncpy( but->val.asstr, newstr, but->slen + 1 ); + + return 0; + } else { MEM_freeN( but->val.asstr ); but->slen = newlen;