Index: libplot/x_afftext.c
--- libplot/x_afftext.c.orig	2008-07-16 02:54:10.000000000 +0200
+++ libplot/x_afftext.c	2015-01-02 10:57:14.194115236 +0100
@@ -185,7 +185,10 @@
   /* invert transformation matrix */
   det = aa[0] * aa[3] - aa[1] * aa[2];
   if (det == 0.0)
+  {
+    free(afftext);
     return NULL;		/* don't support singular matrices */
+  }
   a_inverse[0] =   aa[3] / det;
   a_inverse[1] = - aa[1] / det;
   a_inverse[2] = - aa[2] / det;
@@ -205,7 +208,10 @@
   
   /* paranoia */
   if (size_in.x == 0 || size_in.y == 0)
+  {
+    free(afftext);
     return NULL;
+  }
 
   /* work around a possible bug: some X displays can't create pixmaps that
      are only one pixel wide or high */
@@ -238,7 +244,10 @@
   /* create local image */
   im_in = XAffCreateXImage (dpy, size_in);
   if (im_in == NULL)
+  {
+    free(afftext);
     return NULL;
+  }
 
   /* copy bitmap to it */
   XGetSubImage (dpy, bitmap_in, 0, 0, size_in.x, size_in.y,
@@ -308,7 +317,10 @@
   /* create 2nd image, to hold affinely transformed text */
   im_out = XAffCreateXImage (dpy, size_out);
   if (im_out == NULL)
+  {
+    free(afftext);
     return NULL;
+  }
     
   /* copy from 1st image to this new one */
 
Index: libplot/z_write.c
--- libplot/z_write.c.orig	2008-07-16 02:54:10.000000000 +0200
+++ libplot/z_write.c	2015-01-02 10:57:14.194115236 +0100
@@ -164,7 +164,7 @@
     }
 
   /* cleanup after libpng errors (error handler does a longjmp) */
-  if (setjmp (png_ptr->jmpbuf))
+  if (setjmp (png_jmpbuf(png_ptr)))
     {
       png_destroy_write_struct (&png_ptr, (png_info **)NULL);
       return -1;
@@ -444,7 +444,7 @@
 #endif
     }
 
-  longjmp (png_ptr->jmpbuf, 1);
+  longjmp (png_jmpbuf(png_ptr), 1);
 }
 
 static void 
@@ -515,7 +515,7 @@
 #endif
     }
 
-  longjmp (png_ptr->jmpbuf, 1);
+  longjmp (png_jmpbuf(png_ptr), 1);
 }
 
 static void 
Index: tek2plot/tek2plot.c
--- tek2plot/tek2plot.c.orig	2009-07-30 06:29:14.000000000 +0200
+++ tek2plot/tek2plot.c	2015-01-02 10:57:14.194115236 +0100
@@ -559,7 +559,7 @@
   int temp_three = 0;
 
   /* following variables are saved from point to point */
-  static int saved_lo_y = 0, saved_hi_x = 0, saved_hi_y = 0;
+  static int saved_lo_y = 0, saved_hi_x = 0, saved_hi_y = 0, saved_egm = 0;
   static bool margin_reset = false;
 
   int byte_read, type;
@@ -709,10 +709,12 @@
 	    lo_y = got_lo_y ? lo_y : saved_lo_y;	      
 	    hi_x = got_hi_x ? hi_x : saved_hi_x;
 	    hi_y = got_hi_y ? hi_y : saved_hi_y;
+	    egm = got_egm ? egm : saved_egm;
 	    
 	    saved_lo_y = lo_y;
 	    saved_hi_x = hi_x;
 	    saved_hi_y = hi_y;	      
+	    saved_egm = egm;	      
 	    
 	    /* On a genuine Tektronix 4014, the MSB of the 5-bit EGM
 	       byte sets the margin to equal Margin2 (2048) */
