[Bf-blender-cvs] [73972f2] tmp-id-users: Fix leak when wrong args passed

Campbell Barton noreply at git.blender.org
Wed Jan 6 17:27:33 CET 2016


Commit: 73972f260cf8d3ed74657389293b2e4c7e763a08
Author: Campbell Barton
Date:   Thu Jan 7 03:20:21 2016 +1100
Branches: tmp-id-users
https://developer.blender.org/rB73972f260cf8d3ed74657389293b2e4c7e763a08

Fix leak when wrong args passed

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

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

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

diff --git a/source/blender/python/intern/bpy_rna_id_collection.c b/source/blender/python/intern/bpy_rna_id_collection.c
index 8467c74..91d584f 100644
--- a/source/blender/python/intern/bpy_rna_id_collection.c
+++ b/source/blender/python/intern/bpy_rna_id_collection.c
@@ -127,13 +127,8 @@ static PyObject *bpy_user_map(PyObject *UNUSED(self), PyObject *args, PyObject *
 	static const char *kwlist[] = {"subset", NULL};
 	PyObject *iter_id = NULL;
 
-	PyObject *user_map = PyDict_New();
-
 	IDUserMapData data_cb = {NULL};
 
-	ListBase *lb_array[MAX_LIBARRAY];
-	int lb_idx;
-
 	if (!PyArg_ParseTupleAndKeywords(
 	        args, kwds, "|O:user_map", (char **)kwlist,
 	        &iter_id))
@@ -141,7 +136,7 @@ static PyObject *bpy_user_map(PyObject *UNUSED(self), PyObject *args, PyObject *
 		return NULL;
 	}
 
-	data_cb.user_map = user_map;
+	data_cb.user_map = PyDict_New();
 
 	if (iter_id) {
 		PyObject *fast_it = PySequence_Fast(iter_id, "user_map");
@@ -151,16 +146,19 @@ static PyObject *bpy_user_map(PyObject *UNUSED(self), PyObject *args, PyObject *
 		data_cb.is_subset = true;
 		for (; iter_id_len; ref_id++, iter_id_len--) {
 			PyObject *set = PySet_New(NULL);
-			PyDict_SetItem(user_map, *ref_id, set);
+			PyDict_SetItem(data_cb.user_map, *ref_id, set);
 			Py_DECREF(set);
 		}
 		Py_DECREF(fast_it);
 	}
 
-	lb_idx = set_listbasepointers(bmain, lb_array);
 
-	while (lb_idx--) {
-		for (ID *id = lb_array[lb_idx]->first; id; id = id->next) {
+	ListBase *lb_array[MAX_LIBARRAY];
+	int lb_index;
+	lb_index = set_listbasepointers(bmain, lb_array);
+
+	while (lb_index--) {
+		for (ID *id = lb_array[lb_index]->first; id; id = id->next) {
 			/* One-time init, ID is just used as placeholder here, we abuse this in iterator callback
 			 * to avoid having to rebuild a complete bpyrna object each time for the key searching
 			 * (where only ID pointer value is used). */
@@ -179,7 +177,7 @@ static PyObject *bpy_user_map(PyObject *UNUSED(self), PyObject *args, PyObject *
 
 	Py_XDECREF(data_cb.py_id_key_lookup_only);
 
-	return user_map;
+	return data_cb.user_map;
 }
 
 int BPY_rna_id_collection_module(PyObject *mod_par)




More information about the Bf-blender-cvs mailing list