From 71e7775bcbf4f53ffeade9b34f6e6a8c6946e0e0 Mon Sep 17 00:00:00 2001 From: YimingWu Date: Fri, 26 Apr 2024 06:31:22 +0200 Subject: [PATCH] Fix: Mantaflow: move allocation after early return Varibale `pic` is allowcated before an early return, which could cause a memory leak. Now fixed. Pull Request: https://projects.blender.org/blender/blender/pulls/121104 --- extern/mantaflow/helper/util/simpleimage.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extern/mantaflow/helper/util/simpleimage.cpp b/extern/mantaflow/helper/util/simpleimage.cpp index 5f062bf0150..8150c196ea0 100644 --- a/extern/mantaflow/helper/util/simpleimage.cpp +++ b/extern/mantaflow/helper/util/simpleimage.cpp @@ -152,8 +152,6 @@ bool SimpleImage::initFromPpm(std::string filename) rowsize = windW * 3; } - unsigned char *pic = new unsigned char[size]; // (GLubyte *)malloc (size); - // Read in maximum value (ignore) , could be scanned with sscanf as well, but this should be // 255... 3rd line if (fgets(line, MAXLINE, fp) == nullptr) { @@ -162,6 +160,8 @@ bool SimpleImage::initFromPpm(std::string filename) return 0; } + unsigned char *pic = new unsigned char[size]; // (GLubyte *)malloc (size); + // Read in the pixel array row-by-row: 1st row = top scanline */ unsigned char *ptr = nullptr; ptr = &pic[(windH - 1) * rowsize];