Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-10-31 04:30:56 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-10-31 04:32:57 +0300
commitb1d2db2c774c25048b1fa659efbbe5f95ec2e04f (patch)
tree5b5de857c5e0ab14d1b18953171599cb22b1dd64 /source/blender/python/gpu
parent205eac3038fb0422558bd18dc53c03d2c80b9733 (diff)
Fix leak in successive calls to Batch.program_set
Diffstat (limited to 'source/blender/python/gpu')
-rw-r--r--source/blender/python/gpu/gpu_py_batch.c17
1 files changed, 15 insertions, 2 deletions
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;