summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreeyorp <Freeyorp101@hotmail.com>2009-09-28 16:46:38 +1300
committerFreeyorp <Freeyorp101@hotmail.com>2009-09-28 17:04:51 +1300
commit50c23cbae082f4aba50620e97ab1f08a16f9703d (patch)
treea640829554ad6f8a784d9b11456fb9521f19d94a
parent2c1745f6a0fc3642a986aff5f3e23a79ee96450e (diff)
downloadmana-client-50c23cbae082f4aba50620e97ab1f08a16f9703d.tar.gz
mana-client-50c23cbae082f4aba50620e97ab1f08a16f9703d.tar.bz2
mana-client-50c23cbae082f4aba50620e97ab1f08a16f9703d.tar.xz
mana-client-50c23cbae082f4aba50620e97ab1f08a16f9703d.zip
Fix file handling in imagewriter
Make imagewriter only open a file stream after some checks have occurred elsewhere, and be sure to close it if the surface conversion fails.
-rw-r--r--src/resources/imagewriter.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/resources/imagewriter.cpp b/src/resources/imagewriter.cpp
index 097e0c05..86f92561 100644
--- a/src/resources/imagewriter.cpp
+++ b/src/resources/imagewriter.cpp
@@ -30,12 +30,6 @@
bool ImageWriter::writePNG(SDL_Surface *surface, const std::string &filename)
{
// TODO Maybe someone can make this look nice?
- FILE *fp = fopen(filename.c_str(), "wb");
- if (!fp)
- {
- logger->log("could not open file %s for writing", filename.c_str());
- return false;
- }
png_structp png_ptr;
png_infop info_ptr;
@@ -68,6 +62,13 @@ bool ImageWriter::writePNG(SDL_Surface *surface, const std::string &filename)
return false;
}
+ FILE *fp = fopen(filename.c_str(), "wb");
+ if (!fp)
+ {
+ logger->log("could not open file %s for writing", filename.c_str());
+ return false;
+ }
+
png_init_io(png_ptr, fp);
colortype = (surface->format->BitsPerPixel == 24) ?
@@ -84,6 +85,7 @@ bool ImageWriter::writePNG(SDL_Surface *surface, const std::string &filename)
if (!row_pointers)
{
logger->log("Had trouble converting surface to row pointers");
+ fclose(fp);
return false;
}