From 931146731d896a20b15e1fe847479025b2922db5 Mon Sep 17 00:00:00 2001 From: Antony Riakiotakis Date: Tue, 22 May 2012 17:33:58 +0000 Subject: [PATCH] Fix memory leak when deleting all vertices from mesh with certain modifiers (bevel and array among them) and VBO are enabled. --- source/blender/gpu/intern/gpu_buffers.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c index 833aefc20aa..6da7d9e10e3 100644 --- a/source/blender/gpu/intern/gpu_buffers.c +++ b/source/blender/gpu/intern/gpu_buffers.c @@ -102,7 +102,7 @@ static GPUBufferPool *gpu_buffer_pool_new(void) if (useVBOs == -1) useVBOs = (GLEW_ARB_vertex_buffer_object ? 1 : 0); - pool = MEM_callocN(sizeof(GPUBufferPool), "GPUBuffer"); + pool = MEM_callocN(sizeof(GPUBufferPool), "GPUBuffer_Pool"); pool->maxsize = MAX_FREE_GPU_BUFFERS; pool->buffers = MEM_callocN(sizeof(GPUBuffer *) * pool->maxsize, @@ -192,6 +192,12 @@ GPUBuffer *GPU_buffer_alloc(int size) GPUBuffer *buf; int i, bufsize, bestfit = -1; + /* bad case, leads to leak of buf since buf->pointer will allocate + * NULL, leading to return without cleanup. In any case better detect early + * psy-fi */ + if(size == 0) + return NULL; + pool = gpu_get_global_buffer_pool(); /* not sure if this buffer pool code has been profiled much,