Skip to content

Commit

Permalink
Fixing memory leak converting to PyObject from some SAFEARRAY elements (
Browse files Browse the repository at this point in the history
#2316)

Some SAFEARRAY element types require ownership change when converted to
PyObjects. This includes the BSTR, IUnknown and IDispatch types.
Otherwise the memory gets leaked upon garbage collection.

Co-authored-by: Kyle Johnson <KyleJ61782@gmail.com>
  • Loading branch information
kjpowerworld and KyleJ61782 authored Oct 18, 2024
1 parent c717bfa commit 636e4c0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions com/win32com/src/oleargs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,15 +860,15 @@ static PyObject *PyCom_PyObjectFromSAFEARRAYDimensionItem(SAFEARRAY *psa, VARENU
hres = SafeArrayGetElement(psa, arrayIndices, &str);
if (FAILED(hres))
break;
subitem = PyWinObject_FromBstr(str);
subitem = PyWinObject_FromBstr(str, TRUE);
break;
}
case VT_DISPATCH: {
IDispatch *pDisp;
hres = SafeArrayGetElement(psa, arrayIndices, &pDisp);
if (FAILED(hres))
break;
subitem = PyCom_PyObjectFromIUnknown(pDisp, IID_IDispatch, TRUE);
subitem = PyCom_PyObjectFromIUnknown(pDisp, IID_IDispatch, FALSE);
break;
}
// case VT_ERROR - handled above with I4
Expand All @@ -895,7 +895,7 @@ static PyObject *PyCom_PyObjectFromSAFEARRAYDimensionItem(SAFEARRAY *psa, VARENU
hres = SafeArrayGetElement(psa, arrayIndices, &pUnk);
if (FAILED(hres))
break;
subitem = PyCom_PyObjectFromIUnknown(pUnk, IID_IUnknown, TRUE);
subitem = PyCom_PyObjectFromIUnknown(pUnk, IID_IUnknown, FALSE);
break;
}
// case VT_DECIMAL
Expand Down

0 comments on commit 636e4c0

Please sign in to comment.