diff src/DLD-FUNCTIONS/__voronoi__.cc @ 14339:3e4350f09a55 stable

close temporary files opened for Qhull * __delaunay__.cc (close_fcn): New static function. (F__delaunay__): Add close_fcn and outfile to unwind protect stack. * __voronoi__.cc (close_fcn): New static function. (F__voronoi__): Add close_fcn and outfile to unwind protect stack. * convhull.cc (close_fcn): New static function. (Fconvhull): Add close_fcn and outfile to unwind protect stack.
author John W. Eaton <jwe@octave.org>
date Mon, 06 Feb 2012 15:54:10 -0500
parents 824e5d362aba
children 60e5cf354d80
line wrap: on
line diff
--- a/src/DLD-FUNCTIONS/__voronoi__.cc	Mon Feb 06 15:27:00 2012 -0500
+++ b/src/DLD-FUNCTIONS/__voronoi__.cc	Mon Feb 06 15:54:10 2012 -0500
@@ -44,6 +44,7 @@
 #include "defun-dld.h"
 #include "error.h"
 #include "oct-obj.h"
+#include "unwind-prot.h"
 
 #if defined (HAVE_QHULL)
 # include "oct-qhull.h"
@@ -52,6 +53,12 @@
 # endif
 #endif
 
+static void
+close_fcn (FILE *f)
+{
+  gnulib::fclose (f);
+}
+
 DEFUN_DLD (__voronoi__, args, ,
         "-*- texinfo -*-\n\
 @deftypefn  {Loadable Function} {@var{C}, @var{F} =} __voronoi__ (@var{caller}, @var{pts})\n\
@@ -115,6 +122,8 @@
 
   boolT ismalloc = false;
 
+  unwind_protect frame;
+
   // Replace the outfile pointer with stdout for debugging information.
 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)
   FILE *outfile = gnulib::fopen ("NUL", "w");
@@ -122,10 +131,12 @@
   FILE *outfile = gnulib::fopen ("/dev/null", "w");
 #endif
   FILE *errfile = stderr;
-      
-  if  (! outfile)
+
+  if (outfile)
+    frame.add_fcn (close_fcn, outfile);
+  else
     {
-      error ("__voronoi__: Unable to create temporary file for output.");
+      error ("__voronoi__: unable to create temporary file for output");
       return retval;
     }