From 7f46535cce2ca2cd23af618be386a23c98c5afe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= <1671644+arrufat@users.noreply.github.com> Date: Tue, 14 Jun 2022 20:59:38 +0900 Subject: [PATCH] Fix potential memory leak when writing WebP throws (#2600) --- dlib/image_saver/save_webp.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dlib/image_saver/save_webp.cpp b/dlib/image_saver/save_webp.cpp index e1ee2118c..ea9a8a5ba 100644 --- a/dlib/image_saver/save_webp.cpp +++ b/dlib/image_saver/save_webp.cpp @@ -74,7 +74,10 @@ namespace dlib { { fout.write(reinterpret_cast(output), output_size); if (!fout.good()) + { + WebPFree(output); throw image_save_error("Error while writing WebP image to " + filename + "."); + } } else {