From 50c8a0c91a1dd2fad6f6c7f86283f0dc9760a29e Mon Sep 17 00:00:00 2001 From: scuri Date: Mon, 23 Nov 2009 17:11:42 +0000 Subject: Fixed: memory leak in imFileOpen. --- html/en/history.html | 4 +++- include/im.h | 2 +- src/im_file.cpp | 3 ++- src/im_format.cpp | 23 ++++++++++++++++++----- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/html/en/history.html b/html/en/history.html index fdf2b46..76df670 100644 --- a/html/en/history.html +++ b/html/en/history.html @@ -12,11 +12,13 @@

History of Changes

- CVS (20/11/2009

+ CVS (23/11/2009

Version 3.5 (02/Oct/2009)

diff --git a/include/im.h b/include/im.h index a324199..307e0a3 100644 --- a/include/im.h +++ b/include/im.h @@ -235,7 +235,7 @@ int imFileWriteImageData(imFile* ifile, void* data); * \ingroup format */ void imFormatRegisterInternal(void); -/** Remove all registered formats. +/** Remove all registered formats. Call this if you are checking memory leaks. * \ingroup format */ void imFormatRemoveAll(void); diff --git a/src/im_file.cpp b/src/im_file.cpp index 3bfa779..9a4519a 100644 --- a/src/im_file.cpp +++ b/src/im_file.cpp @@ -2,7 +2,7 @@ * \brief File Access * * See Copyright Notice in im_lib.h - * $Id: im_file.cpp,v 1.5 2009/08/23 23:57:51 scuri Exp $ + * $Id: im_file.cpp,v 1.6 2009/11/23 17:13:05 scuri Exp $ */ #include @@ -125,6 +125,7 @@ void imFileClose(imFile* ifile) if (ifile->line_buffer) free(ifile->line_buffer); delete attrib_table; + delete ifileformat; } void* imFileHandle(imFile* ifile, int index) diff --git a/src/im_format.cpp b/src/im_format.cpp index d389743..ad04a3b 100644 --- a/src/im_format.cpp +++ b/src/im_format.cpp @@ -2,7 +2,7 @@ * \brief File Format Access * * See Copyright Notice in im_lib.h - * $Id: im_format.cpp,v 1.2 2008/12/03 15:45:34 scuri Exp $ + * $Id: im_format.cpp,v 1.3 2009/11/23 17:13:05 scuri Exp $ */ @@ -194,7 +194,7 @@ imFileFormatBase* imFileFormatBaseOpen(const char* file_name, int *error) imFileFormatBase* ifileformat = iformat->Create(); *error = ifileformat->Open(file_name); if (*error != IM_ERR_NONE && *error != IM_ERR_FORMAT) // Error situation that must abort - { // Only IM_ERR_FORMAT is a valid error here + { // Only IM_ERR_FORMAT is considered here free(extension); delete [] ext_mark; delete ifileformat; @@ -206,6 +206,11 @@ imFileFormatBase* imFileFormatBaseOpen(const char* file_name, int *error) delete [] ext_mark; return ifileformat; } + else + { + /* Other errors, release the format and test another one */ + delete ifileformat; + } } } @@ -233,6 +238,11 @@ imFileFormatBase* imFileFormatBaseOpen(const char* file_name, int *error) delete [] ext_mark; return ifileformat; } + else + { + /* Other errors, release the format and test another one */ + delete ifileformat; + } } } @@ -269,9 +279,12 @@ imFileFormatBase* imFileFormatBaseOpenAs(const char* file_name, const char* form } else if (*error == IM_ERR_NONE) // Sucessfully oppened the file return ifileformat; - - *error = IM_ERR_FORMAT; - return NULL; + else + { + *error = IM_ERR_FORMAT; + delete ifileformat; + return NULL; + } } imFileFormatBase* imFileFormatBaseNew(const char* file_name, const char* format, int *error) -- cgit v1.2.3