PyAPI: fix memory leaks in dictionary assignment
Thanks to Kévin Dietrich for spotting driver leak, checked other uses of PyDict_SetItem and found more.
This commit is contained in:
@@ -356,10 +356,10 @@ static PyGetSetDef bpy_app_getsets[] = {
|
||||
static void py_struct_seq_getset_init(void)
|
||||
{
|
||||
/* tricky dynamic members, not to py-spec! */
|
||||
PyGetSetDef *getset;
|
||||
|
||||
for (getset = bpy_app_getsets; getset->name; getset++) {
|
||||
PyDict_SetItemString(BlenderAppType.tp_dict, getset->name, PyDescr_NewGetSet(&BlenderAppType, getset));
|
||||
for (PyGetSetDef *getset = bpy_app_getsets; getset->name; getset++) {
|
||||
PyObject *item = PyDescr_NewGetSet(&BlenderAppType, getset);
|
||||
PyDict_SetItemString(BlenderAppType.tp_dict, getset->name, item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
}
|
||||
/* end dynamic bpy.app */
|
||||
|
||||
@@ -110,9 +110,11 @@ static void bpy_pydriver_update_dict(const float evaltime)
|
||||
bpy_pydriver_InternStr__frame = PyUnicode_FromString("frame");
|
||||
}
|
||||
|
||||
PyObject *item = PyFloat_FromDouble(evaltime);
|
||||
PyDict_SetItem(bpy_pydriver_Dict,
|
||||
bpy_pydriver_InternStr__frame,
|
||||
PyFloat_FromDouble(evaltime));
|
||||
item);
|
||||
Py_DECREF(item);
|
||||
|
||||
bpy_pydriver_evaltime_prev = evaltime;
|
||||
}
|
||||
@@ -301,7 +303,10 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime)
|
||||
|
||||
/* try to add to dictionary */
|
||||
/* if (PyDict_SetItemString(driver_vars, dvar->name, driver_arg)) { */
|
||||
if (PyDict_SetItem(driver_vars, PyTuple_GET_ITEM(expr_vars, i++), driver_arg) < 0) {
|
||||
if (PyDict_SetItem(driver_vars, PyTuple_GET_ITEM(expr_vars, i++), driver_arg) != -1) {
|
||||
Py_DECREF(driver_arg);
|
||||
}
|
||||
else {
|
||||
/* this target failed - bad name */
|
||||
if (targets_ok) {
|
||||
/* first one - print some extra info for easier identification */
|
||||
|
||||
@@ -264,8 +264,13 @@ static PyObject *bpy_lib_enter(BPy_Library *self, PyObject *UNUSED(args))
|
||||
if (BKE_idcode_is_linkable(code)) {
|
||||
const char *name_plural = BKE_idcode_to_name_plural(code);
|
||||
PyObject *str = PyUnicode_FromString(name_plural);
|
||||
PyDict_SetItem(self->dict, str, PyList_New(0));
|
||||
PyDict_SetItem(from_dict, str, _bpy_names(self, code));
|
||||
PyObject *item;
|
||||
|
||||
PyDict_SetItem(self->dict, str, item = PyList_New(0));
|
||||
Py_DECREF(item);
|
||||
PyDict_SetItem(from_dict, str, item = _bpy_names(self, code));
|
||||
Py_DECREF(item);
|
||||
|
||||
Py_DECREF(str);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user