CVS update by stephent xemacs/src ...

xemacs-cvs at xemacs.org xemacs-cvs at xemacs.org
Wed Feb 21 05:49:37 EST 2007


  User: stephent
  Date: 07/02/21 11:49:37

  Modified:    xemacs/src ChangeLog glyphs-eimage.c
Log:
Fix error handling in png_instantiate. <871wkjn5in.fsf at uwakimon.sk.tsukuba.ac.jp>

Revision  Changes    Path
1.1047    +6 -0      XEmacs/xemacs/src/ChangeLog

Index: ChangeLog
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/ChangeLog,v
retrieving revision 1.1046
retrieving revision 1.1047
diff -u -p -r1.1046 -r1.1047
--- ChangeLog	2007/02/19 14:10:43	1.1046
+++ ChangeLog	2007/02/21 10:49:30	1.1047
@@ -1,3 +1,9 @@
+2007-02-17  Stephen J. Turnbull  <stephen at xemacs.org>
+
+	* glyphs-eimage.c (png_instantiate_unwind): Avoid recursion.
+	(png_instantiate): Initialize setjmp_buffer early, and avoid
+	recursive entry to error handler.
+
 2007-02-19  Stephen J. Turnbull  <stephen at xemacs.org>
 
 	* specifier.c (Fdevice_matching_specifier_tag_list):



1.29      +25 -17    XEmacs/xemacs/src/glyphs-eimage.c

Index: glyphs-eimage.c
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/src/glyphs-eimage.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -p -r1.28 -r1.29
--- glyphs-eimage.c	2006/12/11 10:04:30	1.28
+++ glyphs-eimage.c	2007/02/21 10:49:33	1.29
@@ -849,7 +849,13 @@ png_instantiate_unwind (Lisp_Object unwi
 
   free_opaque_ptr (unwind_obj);
   if (data->png_ptr)
-    png_destroy_read_struct (&(data->png_ptr), &(data->info_ptr), (png_infopp)NULL);
+    {
+      /* ensure we can't get here again */
+      png_structp tmp = data->png_ptr;
+      data->png_ptr = NULL;
+      png_destroy_read_struct (&tmp, &(data->info_ptr), (png_infopp)NULL);
+    }
+
   if (data->instream)
     retry_fclose (data->instream);
 
@@ -874,24 +880,36 @@ png_instantiate (Lisp_Object image_insta
   png_structp png_ptr;
   png_infop info_ptr;
 
+  xzero (unwind);
+  record_unwind_protect (png_instantiate_unwind, make_opaque_ptr (&unwind));
+
+  if (setjmp (png_err_stct.setjmp_buffer))
+    {
+      /* Something blew up:
+	 just display the error (cleanup happens in the unwind) */
+      signal_image_error_2 ("Error decoding PNG",
+			     build_string(png_err_stct.err_str),
+			     instantiator);
+    }
+
   /* Initialize all PNG structures */
-  png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, (void*)&png_err_stct,
+  png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
+				    (void *) &png_err_stct,
 				    png_error_func, png_warning_func);
   if (!png_ptr)
     signal_image_error ("Error obtaining memory for png_read", instantiator);
+  unwind.png_ptr = png_ptr;
+
   info_ptr = png_create_info_struct (png_ptr);
   if (!info_ptr)
     {
+      unwind.png_ptr = NULL;	/* avoid re-calling png_destroy_read_struct
+				   when unwinding */
       png_destroy_read_struct (&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
       signal_image_error ("Error obtaining memory for png_read", instantiator);
     }
-
-  xzero (unwind);
-  unwind.png_ptr = png_ptr;
   unwind.info_ptr = info_ptr;
 
-  record_unwind_protect (png_instantiate_unwind, make_opaque_ptr (&unwind));
-
   /* This code is a mixture of stuff from Ben's GIF/JPEG stuff from
      this file, example.c from the libpng 0.81 distribution, and the
      pngtopnm sources. -WMP-
@@ -899,16 +917,6 @@ png_instantiate (Lisp_Object image_insta
   /* It has been further modified to handle the API changes for 0.96,
      and is no longer usable for previous versions. jh
   */
-
-  /* Set the jmp_buf return context for png_error ... if this returns !0, then
-     we ran into a problem somewhere, and need to clean up after ourselves. */
-  if (setjmp (png_err_stct.setjmp_buffer))
-    {
-      /* Something blew up: just display the error (cleanup happens in the unwind) */
-      signal_image_error_2 ("Error decoding PNG",
-			     build_string(png_err_stct.err_str),
-			     instantiator);
-    }
 
   /* Initialize the IO layer and read in header information */
   {





More information about the XEmacs-CVS mailing list