diff --git a/Contrib/zip2exe/zlib/unzip.c b/Contrib/zip2exe/zlib/unzip.c index 7c01855b..0eee83ed 100644 --- a/Contrib/zip2exe/zlib/unzip.c +++ b/Contrib/zip2exe/zlib/unzip.c @@ -514,10 +514,9 @@ extern unzFile ZEXPORT unzOpen (path) extern int ZEXPORT unzClose (file) unzFile file; { - unz_s* s; - if (file==NULL) + unz_s* s = (unz_s*) file; + if (!s) return UNZ_PARAMERROR; - s=(unz_s*)file; if (s->pfile_in_zip_read!=NULL) unzCloseCurrentFile(file); diff --git a/Docs/src/history.but b/Docs/src/history.but index 0149ba9d..7cd78fad 100644 --- a/Docs/src/history.but +++ b/Docs/src/history.but @@ -14,6 +14,8 @@ Released on ?, 2013 \b Reduced !include/!insertmacro recursion stack usage (\W{http://sourceforge.net/support/tracker.php?aid=3067954}{bug #3067954}) +\b Fixed minor MakeNSIS leaks (\W{http://sourceforge.net/support/tracker.php?aid=3474662}{bug #3474662}) + \S2{} Translations \b Changed LANGFILE macro in LangFile.nsh diff --git a/Source/icon.cpp b/Source/icon.cpp index e503ff85..182cbd39 100644 --- a/Source/icon.cpp +++ b/Source/icon.cpp @@ -24,14 +24,20 @@ static FILE * open_icon(const TCHAR* filename, IconGroupHeader& igh) throw runtime_error("can't open file"); if (!fread(&igh, sizeof(IconGroupHeader), 1, f)) + { + fclose(f); throw runtime_error("unable to read header from file"); + } FIX_ENDIAN_INT16_INPLACE(igh.wIsIcon); FIX_ENDIAN_INT16_INPLACE(igh.wReserved); FIX_ENDIAN_INT16_INPLACE(igh.wCount); if (igh.wIsIcon != 1 || igh.wReserved != 0) + { + fclose(f); throw runtime_error("invalid icon file"); + } return f; } @@ -89,6 +95,7 @@ IconGroup load_icon_file(const TCHAR* filename) IconGroup result; FILE *file = open_icon(filename, iconHeader); + MANAGE_WITH(file, fclose); for (WORD i = 0; i < iconHeader.wCount; i++) { diff --git a/Source/script.cpp b/Source/script.cpp index 38fc729a..2b230e1d 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -1390,6 +1390,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (_fputts(text, fp) < 0) { + fclose(fp); ERROR_MSG(_T("!appendfile: error writing to \"%s\".\n"), file); return PS_ERROR; } diff --git a/Source/util.cpp b/Source/util.cpp index ef8f1687..b9c2b716 100644 --- a/Source/util.cpp +++ b/Source/util.cpp @@ -145,20 +145,20 @@ int update_bitmap(CResourceEditor* re, WORD id, const TCHAR* filename, int width dwSize -= 14; unsigned char* bitmap = (unsigned char*)malloc(dwSize); - if (!bitmap) throw bad_alloc(); - - fseek(f, 14, SEEK_SET); - if (fread(bitmap, 1, dwSize, f) != dwSize) { + if (!bitmap) { fclose(f); - return -2; + throw bad_alloc(); } + + bool gotbmdata = !fseek(f, 14, SEEK_SET) && dwSize == fread(bitmap, 1, dwSize, f); + int retval = gotbmdata ? 0 : -2; fclose(f); - re->UpdateResource(RT_BITMAP, id, NSIS_DEFAULT_LANG, bitmap, dwSize); + if (gotbmdata) + re->UpdateResource(RT_BITMAP, id, NSIS_DEFAULT_LANG, bitmap, dwSize); free(bitmap); - - return 0; + return retval; } #ifndef _WIN32 @@ -717,6 +717,7 @@ static bool GetDLLVersionUsingRE(const tstring& filepath, DWORD& high, DWORD & l free(dll); return 0; } + fclose(fdll); try {