diff --git a/contrib/examples/pngtopng.c b/contrib/examples/pngtopng.c index 4acf6b3ad..1d8333042 100644 --- a/contrib/examples/pngtopng.c +++ b/contrib/examples/pngtopng.c @@ -59,26 +59,27 @@ int main(int argc, const char **argv) else fprintf(stderr, "pngtopng: write %s: %s\n", argv[2], image.message); - - free(buffer); } else - { fprintf(stderr, "pngtopng: read %s: %s\n", argv[1], image.message); - /* This is the only place where a 'free' is required; libpng does - * the cleanup on error and success, but in this case we couldn't - * complete the read because of running out of memory. - */ - png_image_free(&image); - } + free(buffer); } else + { fprintf(stderr, "pngtopng: out of memory: %lu bytes\n", (unsigned long)PNG_IMAGE_SIZE(image)); + + /* This is the only place where a 'free' is required; libpng does + * the cleanup on error and success, but in this case we couldn't + * complete the read because of running out of memory and so libpng + * has not got to the point where it can do cleanup. + */ + png_image_free(&image); + } } else