The Independent JPEG Group's JPEG software v3
diff --git a/jerror.c b/jerror.c
index f719dbc..2302312 100644
--- a/jerror.c
+++ b/jerror.c
@@ -1,7 +1,7 @@
 /*
  * jerror.c
  *
- * Copyright (C) 1991, Thomas G. Lane.
+ * Copyright (C) 1991, 1992, Thomas G. Lane.
  * This file is part of the Independent JPEG Group's software.
  * For conditions of distribution and use, see the accompanying README file.
  *
@@ -13,9 +13,9 @@
  * The error_exit() routine should not return to its caller.  Within a
  * larger application, you might want to have it do a longjmp() to return
  * control to the outer user interface routine.  This should work since
- * the portable JPEG code doesn't use setjmp/longjmp.  However, this won't
- * release allocated memory or close temp files --- some bookkeeping would
- * need to be added to the memory manager module to make that work.
+ * the portable JPEG code doesn't use setjmp/longjmp.  You should make sure
+ * that free_all is called either within error_exit or after the return to
+ * the outer-level routine.
  *
  * These routines are used by both the compression and decompression code.
  */
@@ -25,8 +25,12 @@
 #include <stdlib.h>		/* to declare exit() */
 #endif
 
+#ifndef EXIT_FAILURE		/* define exit() codes if not provided */
+#define EXIT_FAILURE  1
+#endif
 
-static external_methods_ptr methods; /* saved for access to message_parm */
+
+static external_methods_ptr methods; /* saved for access to message_parm, free_all */
 
 
 METHODDEF void
@@ -45,7 +49,8 @@
 error_exit (const char *msgtext)
 {
   trace_message(msgtext);
-  exit(1);
+  (*methods->free_all) ();	/* clean up memory allocation */
+  exit(EXIT_FAILURE);
 }
 
 
@@ -58,7 +63,7 @@
 GLOBAL void
 jselerror (external_methods_ptr emethods)
 {
-  methods = emethods;		/* save struct addr for msg parm access */
+  methods = emethods;		/* save struct addr for later access */
 
   emethods->error_exit = error_exit;
   emethods->trace_message = trace_message;