diff libinterp/corefcn/gl2ps-print.cc @ 23740:38188d1aaf3f

ensure that temporary file used by gl2ps is closed (bug #50696) * gl2ps-print.cc (gl2ps_renderer:draw): Use unwind-protect to ensure that temporary file is closed.
author John W. Eaton <jwe@octave.org>
date Thu, 06 Jul 2017 16:25:38 -0400
parents 08036a7f3660
children 7a1097510439
line wrap: on
line diff
--- a/libinterp/corefcn/gl2ps-print.cc	Thu Jul 06 14:23:27 2017 -0400
+++ b/libinterp/corefcn/gl2ps-print.cc	Thu Jul 06 16:25:38 2017 -0400
@@ -48,6 +48,20 @@
 #include "sysdep.h"
 #include "text-renderer.h"
 
+static void
+safe_pclose (FILE *f)
+{
+  if (f)
+    octave_pclose (f);
+}
+
+static void
+safe_fclose (FILE *f)
+{
+  if (f)
+    std::fclose (f);
+}
+
 namespace octave
 {
   class
@@ -238,6 +252,8 @@
         if (! tmpf)
           error ("gl2ps_renderer::draw: couldn't open temporary file for printing");
 
+        frame.add_fcn (safe_fclose, tmpf);
+
         // Reset buffsize, unless this is 2nd pass of a texstandalone print.
         if (term.find ("tex") == std::string::npos)
           buffsize = 2*1024*1024;
@@ -812,20 +828,6 @@
 
 }
 
-static void
-safe_pclose (FILE *f)
-{
-  if (f)
-    octave_pclose (f);
-}
-
-static void
-safe_fclose (FILE *f)
-{
-  if (f)
-    std::fclose (f);
-}
-
 #endif
 
 namespace octave