tools/python: Fix memory leak on error path

Commit 56a7aaa16b introduced a memory leak on the error path for a
Py_BuildValue built object that on some newly introduced error path
has not the correct reference count handling, fix that by decrementing
the refcount in these path.

Fixes: 56a7aaa16b ("tools: add physinfo arch_capabilities handling for Arm")
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
This commit is contained in:
Luca Fancellu authored and Julien Grall committed 2023-07-04 20:10:20 +01:00
1 parent 619fe8a261
commit 248fbb9ee2
1 file changed
+7 -2
+7 -2
View File
@@ -919,11 +919,16 @@ static PyObject *pyxc_physinfo(XcObject *self)
sve_vl_bits = arch_capabilities_arm_sve(pinfo.arch_capabilities);
py_arm_sve_vl = PyLong_FromUnsignedLong(sve_vl_bits);
if ( !py_arm_sve_vl )
if ( !py_arm_sve_vl ) {
Py_DECREF(objret);
return NULL;
}
if( PyDict_SetItemString(objret, "arm_sve_vl", py_arm_sve_vl) )
if( PyDict_SetItemString(objret, "arm_sve_vl", py_arm_sve_vl) ) {
Py_DECREF(py_arm_sve_vl);
Py_DECREF(objret);
return NULL;
}
}
#endif
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.