From 5fe60f944895175910447f7e584a7d4f788c0ff7 Mon Sep 17 00:00:00 2001 From: Cary Phillips Date: Wed, 28 Feb 2024 09:25:58 -0800 Subject: [PATCH] Fix memory leaks in exrstdattr and example code (#1649) Caught by the address sanitizer, worth addressing in the example code as good programming practice. Signed-off-by: Cary Phillips --- src/bin/exrstdattr/main.cpp | 3 +++ src/examples/multipartExamples.cpp | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/bin/exrstdattr/main.cpp b/src/bin/exrstdattr/main.cpp index 410199391..ab040210f 100644 --- a/src/bin/exrstdattr/main.cpp +++ b/src/bin/exrstdattr/main.cpp @@ -848,6 +848,9 @@ main (int argc, char** argv) outPart.copyPixels (inPart); } } + + for (int i=0; i +void freeDeepBuffers (list> & channels) +{ + for (auto i = channels.begin (); i != channels.end (); i++) + { + Array2D & channel = *i; + for (int y = 0; y < channel.height (); y++) + for (int x = 0; x < channel.width (); x++) + delete[] channel[y][x]; + } +} + template void modifyChannels(list> & channels, T delta) { @@ -474,6 +486,10 @@ void modifyMultipart () outputPart.setFrameBuffer (frameBuffer); outputPart.writeTiles (0, outputPart.numXTiles () - 1, 0, outputPart.numYTiles () - 1); } + + freeDeepBuffers(intChannels); + freeDeepBuffers(halfChannels); + freeDeepBuffers(floatChannels); } } }