[Bf-blender-cvs] [b1d2db2c774] blender2.8: Fix leak in successive calls to Batch.program_set

Campbell Barton noreply at git.blender.org
Wed Oct 31 02:35:28 CET 2018


Commit: b1d2db2c774c25048b1fa659efbbe5f95ec2e04f
Author: Campbell Barton
Date:   Wed Oct 31 12:30:56 2018 +1100
Branches: blender2.8
https://developer.blender.org/rBb1d2db2c774c25048b1fa659efbbe5f95ec2e04f

Fix leak in successive calls to Batch.program_set

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

M	source/blender/python/gpu/gpu_py_batch.c

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

diff --git a/source/blender/python/gpu/gpu_py_batch.c b/source/blender/python/gpu/gpu_py_batch.c
index 051e650de84..ec73028ab92 100644
--- a/source/blender/python/gpu/gpu_py_batch.c
+++ b/source/blender/python/gpu/gpu_py_batch.c
@@ -184,8 +184,21 @@ static PyObject *bpygpu_VertBatch_program_set(BPyGPUBatch *self, BPyGPUShader *p
 	        GPU_shader_get_interface(shader));
 
 #ifdef USE_GPU_PY_REFERENCES
-	/* Hold user */
-	PyList_Append(self->references, (PyObject *)py_shader);
+	/* Remove existing user (if any), hold new user. */
+	int i = PyList_GET_SIZE(self->references);
+	while (--i != -1) {
+		PyObject *py_shader_test = PyList_GET_ITEM(self->references, i);
+		if (BPyGPUShader_Check(py_shader_test)) {
+			PyList_SET_ITEM(self->references, i, (PyObject *)py_shader);
+			Py_INCREF(py_shader);
+			Py_DECREF(py_shader_test);
+			/* Only ever reference one shader. */
+			break;
+		}
+	}
+	if (i != -1) {
+		PyList_Append(self->references, (PyObject *)py_shader);
+	}
 #endif
 
 	Py_RETURN_NONE;



More information about the Bf-blender-cvs mailing list