From 8cb81bd55b962e8165890424242e55a3b8fbd412 Mon Sep 17 00:00:00 2001 From: Dave Beazley Date: Wed, 12 Jul 2000 20:05:08 +0000 Subject: [PATCH] Fixed memory leak in Python pointer type-checking code. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@573 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Lib/python/python.swg | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/SWIG/Lib/python/python.swg b/SWIG/Lib/python/python.swg index 10218dccd..610515452 100644 --- a/SWIG/Lib/python/python.swg +++ b/SWIG/Lib/python/python.swg @@ -267,6 +267,7 @@ SWIG_ConvertPtr(PyObject *obj, void **ptr, _swig_type_info *ty, int flags) { _swig_type_info *tc; char *c; static PyObject *SWIG_this = 0; + int newref = 0; if (!obj || (obj == Py_None)) { *ptr = 0; @@ -277,10 +278,16 @@ SWIG_ConvertPtr(PyObject *obj, void **ptr, _swig_type_info *ty, int flags) { if (!SWIG_this) SWIG_this = PyString_InternFromString("this"); obj = PyObject_GetAttr(obj,SWIG_this); - if ((!obj) || !(PyCObject_Check(obj))) goto type_error; + newref = 1; + if (!obj) goto type_error; + if (!PyCObject_Check(obj)) { + Py_DECREF(obj); + goto type_error; + } } *ptr = PyCObject_AsVoidPtr(obj); c = (char *) PyCObject_GetDesc(obj); + if (newref) Py_DECREF(obj); goto cobject; #else if (!(PyString_Check(obj))) { @@ -324,6 +331,7 @@ cobject: return 0; type_error: + if (flags) { if (ty) { char *temp = (char *) malloc(64+strlen(ty->name));