From ebbd7a1ffb66e5f99c7ace35b2eafb3b12c017d7 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 6 Dec 2024 03:57:29 +0100 Subject: [PATCH] opj_compress: fix memory leak in error code path (when cannot create output file) Fixes #1567 --- src/bin/jp2/opj_compress.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index c3d7f4fba..7de978690 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -2249,6 +2249,9 @@ int main(int argc, char **argv) /* open a byte stream for writing and allocate memory for all tiles */ l_stream = opj_stream_create_default_file_stream(parameters.outfile, OPJ_FALSE); if (! l_stream) { + fprintf(stderr, "cannot create %s\n", parameters.outfile); + opj_destroy_codec(l_codec); + opj_image_destroy(image); ret = 1; goto fin; } @@ -2263,6 +2266,9 @@ int main(int argc, char **argv) OPJ_UINT32 l_data_size = 512 * 512 * 3; l_data = (OPJ_BYTE*) calloc(1, l_data_size); if (l_data == NULL) { + opj_stream_destroy(l_stream); + opj_destroy_codec(l_codec); + opj_image_destroy(image); ret = 1; goto fin; }