Index: gif2png.c
--- gif2png.c.orig
+++ gif2png.c
@@ -138,6 +138,19 @@ static int writefile(struct GIFelement *s, struct GIFe
     png_text software;
     png_text comment;
 
+    png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+    if (png_ptr == NULL) {
+      fprintf(stderr, "gif2png: fatal error, out of memory\n");
+      fprintf(stderr, "gif2png: exiting ungracefully\n");
+      exit(1);
+    }
+    info_ptr = png_create_info_struct(png_ptr);
+    if (info_ptr == NULL) {
+      fprintf(stderr, "gif2png: fatal error, out of memory\n");
+      fprintf(stderr, "gif2png: exiting ungracefully\n");
+      exit(1);
+    }
+
     /* these volatile declarations prevent gcc warnings ("variable might be
      *  clobbered by `longjmp' or `vfork'") */
     volatile bool gray = true;
