diff options
| author | Manolo Gouy <Manolo> | 2011-05-12 08:07:27 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2011-05-12 08:07:27 +0000 |
| commit | 622b357f24ed98769e7006225690bfdbb6648e83 (patch) | |
| tree | 991461238bd2cd719d81a65ca0417c0523bae63e /src | |
| parent | bcbb26d5e763146869df12b0390f502ec25f21f9 (diff) | |
Fix STR #2625: removed memory leak after reading erroneous PNG data.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8656 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_PNG_Image.cxx | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/Fl_PNG_Image.cxx b/src/Fl_PNG_Image.cxx index 1ac8dbef2..6ba33ae64 100644 --- a/src/Fl_PNG_Image.cxx +++ b/src/Fl_PNG_Image.cxx @@ -123,14 +123,23 @@ void Fl_PNG_Image::load_png_(const char *name_png, const unsigned char *buffer_p if (!from_memory) { if ((fp = fl_fopen(name_png, "rb")) == NULL) return; } + else name_png = "In-memory PNG data"; // Setup the PNG data structures... - pp = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - info = png_create_info_struct(pp); - + pp = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (pp) info = png_create_info_struct(pp); + if (!pp || !info) { + if (pp) png_destroy_read_struct(&pp, NULL, NULL); + if (!from_memory) fclose(fp); + Fl::warning("Cannot allocate memory to read PNG file or data \"%s\".\n", name_png); + return; + } + if (setjmp(png_jmpbuf(pp))) { - Fl::warning("PNG file \"%s\" contains errors!\n", name_png); + png_destroy_read_struct(&pp, &info, NULL); + if (!from_memory) fclose(fp); + Fl::warning("PNG file or data \"%s\" contains errors!\n", name_png); return; } |
