- fixed more memory leaks found in texture readers

This commit is contained in:
Mark Vejvoda
2010-09-07 21:53:45 +00:00
parent 958184e018
commit 4ed2e4b013
2 changed files with 10 additions and 5 deletions

View File

@@ -64,20 +64,24 @@ Pixmap2D* PNGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const
is.read((char*)buffer, 8); is.read((char*)buffer, 8);
if (png_sig_cmp(buffer, 0, 8) != 0) { if (png_sig_cmp(buffer, 0, 8) != 0) {
delete [] buffer;
return NULL; //This is not a PNG file - could be used for fast checking whether file is supported or not return NULL; //This is not a PNG file - could be used for fast checking whether file is supported or not
} }
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) { if (!png_ptr) {
delete [] buffer;
return NULL; return NULL;
} }
png_infop info_ptr = png_create_info_struct(png_ptr); png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) { if (!info_ptr) {
png_destroy_read_struct(&png_ptr, (png_infopp)NULL,(png_infopp)NULL); png_destroy_read_struct(&png_ptr, (png_infopp)NULL,(png_infopp)NULL);
delete [] buffer;
return NULL; return NULL;
} }
if (setjmp(png_jmpbuf(png_ptr))) { if (setjmp(png_jmpbuf(png_ptr))) {
png_destroy_read_struct(&png_ptr, &info_ptr,(png_infopp)NULL); png_destroy_read_struct(&png_ptr, &info_ptr,(png_infopp)NULL);
delete [] buffer;
return NULL; //Error during init_io return NULL; //Error during init_io
} }
png_set_read_fn(png_ptr, &is, user_read_data); png_set_read_fn(png_ptr, &is, user_read_data);
@@ -104,6 +108,7 @@ Pixmap2D* PNGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const
if (setjmp(png_jmpbuf(png_ptr))) { if (setjmp(png_jmpbuf(png_ptr))) {
delete[] row_pointers; delete[] row_pointers;
delete [] buffer;
return NULL; //error during read_image return NULL; //error during read_image
} }
for (int y = 0; y < height; ++y) { for (int y = 0; y < height; ++y) {
@@ -177,6 +182,8 @@ Pixmap2D* PNGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
delete [] buffer;
return ret; return ret;
} }

View File

@@ -53,9 +53,7 @@ static const int tgaUncompressedBw= 3;
/**Get Extension array, initialised*/ /**Get Extension array, initialised*/
static inline const string* getExtensionStrings() { static inline const string* getExtensionStrings() {
static string * extensions = new string[2]; static const string extensions[] = {"tga", ""};
extensions[0] = "tga";
extensions[1] = "";
return extensions; return extensions;
} }