mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-02 22:11:22 +00:00
COM_LoadMallocFile_TextMode_OSPath: do not leak open file
This commit is contained in:
parent
4df8bb389a
commit
ea4320d675
1 changed files with 12 additions and 4 deletions
|
@ -1886,16 +1886,23 @@ byte *COM_LoadMallocFile_TextMode_OSPath (const char *path, long *len_out)
|
||||||
|
|
||||||
len = COM_filelength (f);
|
len = COM_filelength (f);
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
|
{
|
||||||
|
fclose (f);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
data = (byte *) malloc (len + 1);
|
data = (byte *) malloc (len + 1);
|
||||||
if (data == NULL)
|
if (data == NULL)
|
||||||
|
{
|
||||||
|
fclose (f);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// (actuallen < len) if CRLF to LF translation was performed
|
// (actuallen < len) if CRLF to LF translation was performed
|
||||||
actuallen = fread (data, 1, len, f);
|
actuallen = fread (data, 1, len, f);
|
||||||
if (ferror(f))
|
if (ferror(f))
|
||||||
{
|
{
|
||||||
|
fclose (f);
|
||||||
free (data);
|
free (data);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1903,6 +1910,7 @@ byte *COM_LoadMallocFile_TextMode_OSPath (const char *path, long *len_out)
|
||||||
|
|
||||||
if (len_out != NULL)
|
if (len_out != NULL)
|
||||||
*len_out = actuallen;
|
*len_out = actuallen;
|
||||||
|
fclose (f);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue