Skip to content
Snippets Groups Projects
Commit 9b8eaadd authored by D-AIRY's avatar D-AIRY
Browse files

fixed memleak

parent 70ab15e3
No related branches found
No related tags found
1 merge request!1Version 0.10.1
......@@ -570,7 +570,13 @@ int CConfig::writeFile(const CConfigString & name, CConfigString section, CConfi
fseek(pF, 0, SEEK_END);
UINT fl = ftell(pF);
fseek(pF, 0, SEEK_SET);
char * szData = new char[fl];
char * szData = new char[fl + 1];
if(!szData)
{
printf(COLOR_LRED "Unable to allocate memory (%d) in CConfig::writeFile()" COLOR_RESET "\n", fl + 1);
fclose(pF);
return(-1);
}
fread(szData, 1, fl, pF);
szData[fl] = 0;
fclose(pF);
......@@ -690,10 +696,15 @@ int CConfig::writeFile(const CConfigString & name, CConfigString section, CConfi
}
if(sf && !kf)
{
if(*s_pbDebug)
{
printf(" adding key to section(sp=" COLOR_LCYAN "%d" COLOR_RESET ")\n", sp);
}
FILE * pF = fopen(name.c_str(), "wb");
if(!pF)
{
ErrorFile = name;
mem_delete_a(szData);
return -1;
}
fwrite(szData, 1, sp, pF); // First file part
......@@ -703,6 +714,7 @@ int CConfig::writeFile(const CConfigString & name, CConfigString section, CConfi
fwrite("\n", 1, 1, pF);
fwrite(&szData[sp], 1, fl - sp, pF);
fclose(pF);
mem_delete_a(szData);
return 0;
}
if(!sf)//!(Section found) == Add new
......@@ -715,6 +727,7 @@ int CConfig::writeFile(const CConfigString & name, CConfigString section, CConfi
}
fwrite((CConfigString("\n[") + section + "]\n" + key + " = " + val + "\n").c_str(), sizeof(char), section.length() + key.length() + val.length() + 8, pF);
fclose(pF);
mem_delete_a(szData);
return 0;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment