Fixed resource leaks

This commit is contained in:
Martin Ettl 2014-08-24 03:51:00 +02:00
parent 1ff104641a
commit 882072cf30

View File

@ -1049,13 +1049,22 @@ static void LoadSettings()
if ((f = fopen(filename, "rt")) == NULL) if ((f = fopen(filename, "rt")) == NULL)
return; return;
if (fseek(f, 0, SEEK_END)) if (fseek(f, 0, SEEK_END))
{
fclose(f);
return; return;
}
const long f_size_signed = ftell(f); const long f_size_signed = ftell(f);
if (f_size_signed == -1) if (f_size_signed == -1)
{
fclose(f);
return; return;
}
size_t f_size = (size_t)f_size_signed; size_t f_size = (size_t)f_size_signed;
if (fseek(f, 0, SEEK_SET)) if (fseek(f, 0, SEEK_SET))
{
fclose(f);
return; return;
}
char* f_data = new char[f_size+1]; char* f_data = new char[f_size+1];
f_size = fread(f_data, 1, f_size, f); // Text conversion alter read size so let's not be fussy about return value f_size = fread(f_data, 1, f_size, f); // Text conversion alter read size so let's not be fussy about return value
fclose(f); fclose(f);