From b1d2db2c774c25048b1fa659efbbe5f95ec2e04f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 31 Oct 2018 12:30:56 +1100 Subject: Fix leak in successive calls to Batch.program_set --- source/blender/python/gpu/gpu_py_batch.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'source/blender/python/gpu') 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; -- cgit v1.2.3