[Bf-blender-cvs] [b00bc3c] master: PyAPI: fix leak linking library data

Campbell Barton noreply at git.blender.org
Thu Jul 14 09:35:03 CEST 2016


Commit: b00bc3cbc17b938a90f996b6a5206a876bf898a9
Author: Campbell Barton
Date:   Thu Jul 14 17:38:22 2016 +1000
Branches: master
https://developer.blender.org/rBb00bc3cbc17b938a90f996b6a5206a876bf898a9

PyAPI: fix leak linking library data

===================================================================

M	source/blender/python/intern/bpy_library_load.c

===================================================================

diff --git a/source/blender/python/intern/bpy_library_load.c b/source/blender/python/intern/bpy_library_load.c
index 9c417cf..7ceb99d 100644
--- a/source/blender/python/intern/bpy_library_load.c
+++ b/source/blender/python/intern/bpy_library_load.c
@@ -351,30 +351,30 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
 					/* loop */
 					Py_ssize_t size = PyList_GET_SIZE(ls);
 					Py_ssize_t i;
-					PyObject *item;
-					const char *item_str;
 
 					for (i = 0; i < size; i++) {
-						item = PyList_GET_ITEM(ls, i);
-						item_str = _PyUnicode_AsString(item);
+						PyObject *item_src = PyList_GET_ITEM(ls, i);
+#ifdef USE_RNA_DATABLOCKS
+						PyObject *item_dst = NULL;
+#endif
+						const char *item_idname = _PyUnicode_AsString(item_src);
 
-						// printf("  %s\n", item_str);
+						// printf("  %s\n", item_idname);
 
-						if (item_str) {
-							ID *id = BLO_library_link_named_part(mainl, &(self->blo_handle), idcode, item_str);
+						if (item_idname) {
+							ID *id = BLO_library_link_named_part(mainl, &(self->blo_handle), idcode, item_idname);
 							if (id) {
 #ifdef USE_RNA_DATABLOCKS
 								/* swap name for pointer to the id */
-								Py_DECREF(item);
-								item = PyCapsule_New((void *)id, NULL, NULL);
+								item_dst = PyCapsule_New((void *)id, NULL, NULL);
 #endif
 							}
 							else {
-								bpy_lib_exit_warn_idname(self, name_plural, item_str);
+								bpy_lib_exit_warn_idname(self, name_plural, item_idname);
 								/* just warn for now */
 								/* err = -1; */
 #ifdef USE_RNA_DATABLOCKS
-								item = Py_INCREF_RET(Py_None);
+								item_dst = Py_INCREF_RET(Py_None);
 #endif
 							}
 
@@ -382,16 +382,20 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
 						}
 						else {
 							/* XXX, could complain about this */
-							bpy_lib_exit_warn_type(self, item);
+							bpy_lib_exit_warn_type(self, item_src);
 							PyErr_Clear();
 
 #ifdef USE_RNA_DATABLOCKS
-							item = Py_INCREF_RET(Py_None);
+							item_dst = Py_INCREF_RET(Py_None);
 #endif
 						}
 
 #ifdef USE_RNA_DATABLOCKS
-						PyList_SET_ITEM(ls, i, item);
+						if (item_dst) {
+							/* item_dst must be new or already incref'd */
+							Py_DECREF(item_src);
+							PyList_SET_ITEM(ls, i, item_dst);
+						}
 #endif
 					}
 				}




More information about the Bf-blender-cvs mailing list