Hello,

I've attached a patch that resolves a memory and a resource leak.

Best regards,
Moritz
From fd24b8f8e5fe1d4b80af965fa233576fc5d8a10c Mon Sep 17 00:00:00 2001
From: Moritz Lipp <[email protected]>
Date: Sun, 23 Dec 2012 11:00:15 +0100
Subject: [PATCH] Fix memory and resource leak

This patch fixes a resource leak in imageio/format/j2k.c and a memory leak in
common/imageio_j2k.c in a statement that should not be executed anyway. But
since this case is treated, we should took care of the memory also.
---
 src/common/imageio_j2k.c | 4 +++-
 src/imageio/format/j2k.c | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/common/imageio_j2k.c b/src/common/imageio_j2k.c
index 9cc6378..4cde108 100644
--- a/src/common/imageio_j2k.c
+++ b/src/common/imageio_j2k.c
@@ -161,8 +161,10 @@ dt_imageio_retval_t dt_imageio_open_j2k(dt_image_t *img, 
const char *filename, d
     codec = CODEC_JP2;
   else if(file_format == JPT_CFMT)   /* JPEG 2000, JPIP */
     codec = CODEC_JPT;
-  else
+  else {
+    free(src);
     return DT_IMAGEIO_FILE_CORRUPTED; // can't happen
+  }
 
   /* get a decoder handle */
   dinfo = opj_create_decompress(codec);
diff --git a/src/imageio/format/j2k.c b/src/imageio/format/j2k.c
index 78da6d0..b723410 100644
--- a/src/imageio/format/j2k.c
+++ b/src/imageio/format/j2k.c
@@ -449,6 +449,7 @@ int write_image (dt_imageio_j2k_t *j2k, const char 
*filename, const float *in, v
   if(res < (size_t)codestream_length) /* FIXME */
   {
     fprintf(stderr, "failed to write %d (%s)\n", codestream_length, filename);
+    fclose(f);
     return 1;
   }
   fclose(f);
-- 
1.8.0.2

Attachment: pgpYSo6gDP6tr.pgp
Description: PGP signature

------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
darktable-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/darktable-devel

Reply via email to