4770b0
diff --git a/util/gif2rgb.c b/util/gif2rgb.c
4770b0
index e39f37b..92bf82f 100644
4770b0
--- a/util/gif2rgb.c
4770b0
+++ b/util/gif2rgb.c
4770b0
@@ -171,6 +171,8 @@ static void SaveGif(GifByteType *OutputBuffer,
4770b0
     /* Open stdout for the output file: */
4770b0
     if ((GifFile = EGifOpenFileHandle(1, &Error)) == NULL) {
4770b0
 	PrintGifError(Error);
4770b0
+	free(OutputBuffer);
4770b0
+	GifFreeMapObject(OutputColorMap);
4770b0
 	exit(EXIT_FAILURE);
4770b0
     }
4770b0
 
4770b0
@@ -179,25 +181,34 @@ static void SaveGif(GifByteType *OutputBuffer,
4770b0
 			  OutputColorMap) == GIF_ERROR ||
4770b0
 	EGifPutImageDesc(GifFile,
4770b0
 			 0, 0, Width, Height, false, NULL) ==
4770b0
-	                                                             GIF_ERROR)
4770b0
+	                                                             GIF_ERROR) {
4770b0
 	PrintGifError(Error);
4770b0
+	free(OutputBuffer);
4770b0
+	GifFreeMapObject(OutputColorMap);
4770b0
 	exit(EXIT_FAILURE);
4770b0
+    }
4770b0
 
4770b0
     GifQprintf("\n%s: Image 1 at (%d, %d) [%dx%d]:     ",
4770b0
 	       PROGRAM_NAME, GifFile->Image.Left, GifFile->Image.Top,
4770b0
 	       GifFile->Image.Width, GifFile->Image.Height);
4770b0
 
4770b0
     for (i = 0; i < Height; i++) {
4770b0
-	if (EGifPutLine(GifFile, Ptr, Width) == GIF_ERROR)
4770b0
+	if (EGifPutLine(GifFile, Ptr, Width) == GIF_ERROR) {
4770b0
+	    free(OutputBuffer);
4770b0
+	    GifFreeMapObject(OutputColorMap);
4770b0
 	    exit(EXIT_FAILURE);
4770b0
+	}
4770b0
 	GifQprintf("\b\b\b\b%-4d", Height - i - 1);
4770b0
 
4770b0
 	Ptr += Width;
4770b0
     }
4770b0
 
4770b0
-    if (EGifCloseFile(GifFile, &Error) == GIF_ERROR)
4770b0
+    if (EGifCloseFile(GifFile, &Error) == GIF_ERROR) {
4770b0
 	PrintGifError(Error);
4770b0
+	free(OutputBuffer);
4770b0
+	GifFreeMapObject(OutputColorMap);
4770b0
 	exit(EXIT_FAILURE);
4770b0
+    }
4770b0
 }
4770b0
 
4770b0
 /******************************************************************************
4770b0
diff --git a/util/gifsponge.c b/util/gifsponge.c
4770b0
index 6e248d8..12bce36 100644
4770b0
--- a/util/gifsponge.c
4770b0
+++ b/util/gifsponge.c
4770b0
@@ -73,8 +73,7 @@ int main(int argc, char **argv)
4770b0
      * data; it's *your* responsibility to keep your changes consistent.
4770b0
      * Caveat hacker!
4770b0
      */
4770b0
-    if (EGifSpew(GifFileOut) == GIF_ERROR)
4770b0
-	PrintGifError(GifFileOut->Error);
4770b0
+    EGifSpew(GifFileOut);
4770b0
 
4770b0
     if (DGifCloseFile(GifFileIn, &ErrorCode) == GIF_ERROR)
4770b0
 	PrintGifError(ErrorCode);
4770b0
diff --git a/util/giftool.c b/util/giftool.c
4770b0
index e61281c..fe6325c 100644
4770b0
--- a/util/giftool.c
4770b0
+++ b/util/giftool.c
4770b0
@@ -565,9 +565,9 @@ int main(int argc, char **argv)
4770b0
     for (i = 0; i < GifFileIn->ImageCount; i++)
4770b0
 	(void) GifMakeSavedImage(GifFileOut, &GifFileIn->SavedImages[i]);
4770b0
 
4770b0
-    if (EGifSpew(GifFileOut) == GIF_ERROR)
4770b0
-	PrintGifError(GifFileOut->Error);
4770b0
-    else if (DGifCloseFile(GifFileIn, &ErrorCode) == GIF_ERROR)
4770b0
+    EGifSpew(GifFileOut);
4770b0
+
4770b0
+    if (DGifCloseFile(GifFileIn, &ErrorCode) == GIF_ERROR)
4770b0
 	PrintGifError(ErrorCode);
4770b0
 
4770b0
     return 0;