diff libinterp/corefcn/__tiff__.cc @ 31192:6a2bb6f4e41e

__tiff__.cc (F__tiff_imread__): fixed bug where file was not closed on errors.
author magedrifaat <magedrifaat@gmail.com>
date Sat, 27 Aug 2022 16:23:59 +0200
parents 8ada1e68d961
children c142c153034c
line wrap: on
line diff
--- a/libinterp/corefcn/__tiff__.cc	Fri Aug 26 23:30:55 2022 +0200
+++ b/libinterp/corefcn/__tiff__.cc	Sat Aug 27 16:23:59 2022 +0200
@@ -3557,6 +3557,13 @@
     uint16_t offset = 1;
     
     TIFF *tif = TIFFOpen (args(0).string_value ().c_str (), "r");
+    if (! tif)
+      error ("Failed to open file %s", args(0).string_value ().c_str ());
+    
+    // A simple way to make sure the file will be closed when the function
+    // returns or when an error occurs as the destructor will always be called
+    octave_tiff_handle tiff_handle (tif);
+
     uint16_t dir_count = TIFFNumberOfDirectories (tif);
     uint16_t page = 1;
 
@@ -3612,11 +3619,11 @@
     
     // Set the default region
     uint32NDArray row_region (dim_vector (1, 3));
-    row_region(0) = 0;
+    row_region(0) = 1;
     row_region(1) = 1;
     row_region(2) = image_data.height;
     uint32NDArray col_region (dim_vector (1, 3));
-    col_region(0) = 0;
+    col_region(0) = 1;
     col_region(1) = 1;
     col_region(2) = image_data.width;