From 41808c26bee8dc00105a7c6778aab8e6d6ddcccc Mon Sep 17 00:00:00 2001 From: kichik Date: Fri, 12 Sep 2003 11:16:33 +0000 Subject: [PATCH] More memory clean-ups git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@2901 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/DialogTemplate.cpp | 2 +- Source/ResourceVersionInfo.h | 11 +++++++++++ Source/build.cpp | 2 +- Source/lang.cpp | 11 +++++++---- Source/script.cpp | 16 ++++++++++++++++ Source/strlist.h | 3 ++- Source/util.cpp | 12 ++++++++++-- 7 files changed, 48 insertions(+), 9 deletions(-) diff --git a/Source/DialogTemplate.cpp b/Source/DialogTemplate.cpp index f8c8ab65..99760295 100644 --- a/Source/DialogTemplate.cpp +++ b/Source/DialogTemplate.cpp @@ -210,7 +210,7 @@ CDialogTemplate::~CDialogTemplate() { if (m_szTitle) delete [] m_szTitle; if (m_szFont) - delete [] m_szTitle; + delete [] m_szFont; for (unsigned int i = 0; i < m_vItems.size(); i++) { if (m_vItems[i]->szClass && !IS_INTRESOURCE(m_vItems[i]->szClass)) diff --git a/Source/ResourceVersionInfo.h b/Source/ResourceVersionInfo.h index 2d6b1029..f0cc4775 100644 --- a/Source/ResourceVersionInfo.h +++ b/Source/ResourceVersionInfo.h @@ -24,6 +24,17 @@ struct version_string_list { class CVersionStrigList : public SortedStringListND { public: + ~CVersionStrigList() + { + struct version_string_list *itr = (struct version_string_list *) gr.get(); + int i = gr.getlen() / sizeof(struct version_string_list); + + while (i--) + { + delete itr[i].pChildStrings; + } + } + int add(LANGID langid, int codepage) { char Buff[10]; diff --git a/Source/build.cpp b/Source/build.cpp index f26f0408..ea5b1c6b 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -412,7 +412,7 @@ int CEXEBuild::getcurdbsize() { return cur_datablock->getlen(); } int CEXEBuild::add_string(const char *string, int process/*=1*/) // returns offset in stringblock { - if (!*string) return 0; + if (!string || !*string) return 0; if (*string == '$' && *(string+1) == '(') { int idx = 0; diff --git a/Source/lang.cpp b/Source/lang.cpp index a3587d02..fb91351c 100644 --- a/Source/lang.cpp +++ b/Source/lang.cpp @@ -842,10 +842,13 @@ LanguageTable * CEXEBuild::LoadLangFile(char *filename) { } void CEXEBuild::DeleteLangTable(LanguageTable *table) { - free(table->nlf.m_szName); - free(table->nlf.m_szFont); - free(table->lang_strings); + if (table->nlf.m_szName) + free(table->nlf.m_szName); + if (table->nlf.m_szFont) + free(table->nlf.m_szFont); + delete table->lang_strings; for (int i = 0; i < NLF_STRINGS; i++) { - free(table->nlf.m_szStrings[i]); + if (table->nlf.m_szStrings[i]) + free(table->nlf.m_szStrings[i]); } } \ No newline at end of file diff --git a/Source/script.cpp b/Source/script.cpp index d10f3939..16025b68 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -1205,6 +1205,11 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } rewind(fp); char *data=(char*)malloc(datalen+2); + if (!data) + { + ERROR_MSG("Internal compiler error #12345: LicenseData malloc(%d) failed.\n", datalen+2); + return PS_ERROR; + } char *ldata=data+1; if (fread(ldata,1,datalen,fp) != datalen) { @@ -1220,6 +1225,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) *data = SF_TEXT; int ret = SetLangString(name, lang, data); + free(data); if (ret == PS_WARNING) warning_fl("LicenseLangString \"%s\" set multiple times for %d, wasting space", name, lang); else if (ret == PS_ERROR) @@ -1483,10 +1489,16 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) } rewind(fp); data=(char*)malloc(datalen+2); + if (!data) + { + ERROR_MSG("Internal compiler error #12345: LicenseData malloc(%d) failed.\n", datalen+2); + return PS_ERROR; + } char *ldata=data+1; if (fread(ldata,1,datalen,fp) != datalen) { ERROR_MSG("LicenseData: can't read file.\n"); fclose(fp); + free(data); return PS_ERROR; } fclose(fp); @@ -1509,6 +1521,10 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) cur_page->parms[1] = add_string(data, 0); } + + if (!idx) + free(data); + SCRIPT_MSG("LicenseData: \"%s\"\n",file); } return make_sure_not_in_secorfunc(line.gettoken_str(0), 1); diff --git a/Source/strlist.h b/Source/strlist.h index cc2d2492..dac945c4 100644 --- a/Source/strlist.h +++ b/Source/strlist.h @@ -181,7 +181,8 @@ class SortedStringList int num=gr.getlen()/sizeof(T); for (int i=0; iUpdateResource(RT_BITMAP, MAKEINTRESOURCE(id), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), bitmap, dwSize); + free(bitmap); + return 0; } @@ -158,9 +160,15 @@ int replace_icon(CResourceEditor* re, WORD wIconId, char* filename) fpos_t pos; fgetpos(f, &pos); - if (fseek(f, dwOffset, SEEK_SET)) return -1; + if (fseek(f, dwOffset, SEEK_SET)) { + free(rsrcIconGroup); + return -1; + } BYTE* iconData = (BYTE*)malloc(ige->dwRawSize); - if (!iconData) throw bad_alloc(); + if (!iconData) { + free(rsrcIconGroup); + throw bad_alloc(); + } fread(iconData, sizeof(BYTE), ige->dwRawSize, f); re->UpdateResource(RT_ICON, MAKEINTRESOURCE(i+1), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), iconData, ige->dwRawSize); free(iconData);