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:
authorJeroen Bakker <jeroen@blender.org>2020-10-20 14:43:20 +0300
committerJeroen Bakker <jeroen@blender.org>2020-10-22 11:30:04 +0300
commit92571abf5645ea3156e892ecfa2a08f0ca88cad4 (patch)
tree7561392992f049d67c134444102fd54881af4b70 /source/blender/imbuf
parentcf8642d9fac4cec7d3ee434a5403c2bbc8c5c21c (diff)
GPU: Memory leak when scaling buffers
`imb_gpu_get_data` could reuse `data_rect` when it was already in used (double alloc). making the first use leak. This was detected after enabling OpenGL Texture Limit. Reviewed By: Clément Foucault Differential Revision: https://developer.blender.org/D9280
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r--source/blender/imbuf/intern/util_gpu.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/source/blender/imbuf/intern/util_gpu.c b/source/blender/imbuf/intern/util_gpu.c
index 2826bd63cc1..607ab95f0b4 100644
--- a/source/blender/imbuf/intern/util_gpu.c
+++ b/source/blender/imbuf/intern/util_gpu.c
@@ -97,6 +97,7 @@ static void *imb_gpu_get_data(const ImBuf *ibuf,
{
const bool is_float_rect = (ibuf->rect_float != NULL);
void *data_rect = (is_float_rect) ? (void *)ibuf->rect_float : (void *)ibuf->rect;
+ bool freedata = false;
if (is_float_rect) {
/* Float image is already in scene linear colorspace or non-color data by
@@ -104,7 +105,7 @@ static void *imb_gpu_get_data(const ImBuf *ibuf,
* currently. */
if (ibuf->channels != 4 || !store_premultiplied) {
data_rect = MEM_mallocN(sizeof(float[4]) * ibuf->x * ibuf->y, __func__);
- *r_freedata = true;
+ *r_freedata = freedata = true;
if (data_rect == NULL) {
return NULL;
@@ -124,7 +125,7 @@ static void *imb_gpu_get_data(const ImBuf *ibuf,
* and consistency with float images. */
if (!IMB_colormanagement_space_is_data(ibuf->rect_colorspace)) {
data_rect = MEM_mallocN(sizeof(uchar[4]) * ibuf->x * ibuf->y, __func__);
- *r_freedata = true;
+ *r_freedata = freedata = true;
if (data_rect == NULL) {
return NULL;
@@ -147,6 +148,10 @@ static void *imb_gpu_get_data(const ImBuf *ibuf,
ImBuf *scale_ibuf = IMB_allocFromBuffer(rect, rect_float, ibuf->x, ibuf->y, 4);
IMB_scaleImBuf(scale_ibuf, UNPACK2(rescale_size));
+ if (freedata) {
+ MEM_freeN(data_rect);
+ }
+
data_rect = (is_float_rect) ? (void *)scale_ibuf->rect_float : (void *)scale_ibuf->rect;
*r_freedata = true;
/* Steal the rescaled buffer to avoid double free. */