[pywin32-checkins] /hgroot/pywin32/pywin32: Fix error cleanup in PyIEnumShellItems....
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: <pyw...@li...> - 2012-08-05 00:38:49
|
changeset eb5c1ebf9472 in /hgroot/pywin32/pywin32 details: http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/hgroot/pywin32/pywin32?cmd=changeset;node=eb5c1ebf9472 summary: Fix error cleanup in PyIEnumShellItems.Next() diffstat: com/win32comext/shell/src/PyIEnumShellItems.cpp | 18 +++++++++++------- 1 files changed, 11 insertions(+), 7 deletions(-) diffs (36 lines): diff -r 2e3f7a91ef48 -r eb5c1ebf9472 com/win32comext/shell/src/PyIEnumShellItems.cpp --- a/com/win32comext/shell/src/PyIEnumShellItems.cpp Sat Aug 04 17:56:22 2012 -0400 +++ b/com/win32comext/shell/src/PyIEnumShellItems.cpp Sat Aug 04 20:35:38 2012 -0400 @@ -64,6 +64,9 @@ for ( i = celtFetched; i--; ) { PyObject *ob = PyCom_PyObjectFromIUnknown(rgVar[i], IID_IShellItem, FALSE); + // PyCom_PyObjectFromIUnknown always consumes the COM reference, so set the + // pointer to NULL allowing any remaining interfaces to be released on error. + rgVar[i] = NULL; if ( ob == NULL ) { Py_DECREF(result); @@ -73,14 +76,15 @@ PyTuple_SET_ITEM(result, i, ob); } } - /* ??? Could leak some of the returned interfaces if conversion fails, but how to tell - which ones have already been released when result is DECREF'd ? - Maybe always AddRef and always Release when done ??? - */ - if (result == NULL) + + // Release any remaining interfaces if conversion fails + if (result == NULL){ + PY_INTERFACE_PRECALL; for ( i = celtFetched; i--; ) - rgVar[1]->Release(); - + if (rgVar[i]) + rgVar[i]->Release(); + PY_INTERFACE_POSTCALL; + } delete [] rgVar; return result; } |