diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2022-04-13 02:52:19 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2022-04-13 02:52:50 +0300 |
commit | cd4a9c488f66abccf3e35a33adbf2630a389ae67 (patch) | |
tree | fcffd7b1510bcdaadee5d7e292e6928f6849c5b7 /source/blender/python/gpu | |
parent | 9bc678969aaef5e2343d9362648e9a633d1b6e5e (diff) |
Fix possible pointer being freed without being allocated in pygpu module
The `clear` method can be called before dealloc, which can
mislead buffer ownership.
Diffstat (limited to 'source/blender/python/gpu')
-rw-r--r-- | source/blender/python/gpu/gpu_py_buffer.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/source/blender/python/gpu/gpu_py_buffer.c b/source/blender/python/gpu/gpu_py_buffer.c index 82c9f8f1f04..d3f55517ae7 100644 --- a/source/blender/python/gpu/gpu_py_buffer.c +++ b/source/blender/python/gpu/gpu_py_buffer.c @@ -277,7 +277,10 @@ static int pygpu_buffer__tp_traverse(BPyGPUBuffer *self, visitproc visit, void * static int pygpu_buffer__tp_clear(BPyGPUBuffer *self) { - Py_CLEAR(self->parent); + if (self->parent) { + Py_CLEAR(self->parent); + self->buf.as_void = NULL; + } return 0; } @@ -287,7 +290,7 @@ static void pygpu_buffer__tp_dealloc(BPyGPUBuffer *self) PyObject_GC_UnTrack(self); Py_CLEAR(self->parent); } - else { + else if (self->buf.as_void) { MEM_freeN(self->buf.as_void); } |