mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-23 01:59:43 +01:00
Handle errors from PHYSFS_readBytes()
This fixes a bug where levels in the levels list duplicate if there's an invalid file (such as a folder) in the levels directory. It looks like it happens because we don't free the memory if PHYSFS_readBytes() encounters an error, even though we should. Then we get into Undefined Behavior territory and end up reusing memory, and here it just happens that previously, parsing the entire XML document for each level file was enough to make the loaded file pointer point to garbage that would fail the metadata check, but if we optimize it so we don't parse the entire XML document, it starts reusing memory instead.
This commit is contained in:
parent
9c4c76f609
commit
ec3f937f93
1 changed files with 5 additions and 1 deletions
|
@ -189,7 +189,11 @@ void FILESYSTEM_loadFileToMemory(const char *name, unsigned char **mem,
|
|||
{
|
||||
*mem = (unsigned char*) malloc(length);
|
||||
}
|
||||
PHYSFS_readBytes(handle, *mem, length);
|
||||
int success = PHYSFS_readBytes(handle, *mem, length);
|
||||
if (success == -1)
|
||||
{
|
||||
FILESYSTEM_freeMemory(mem);
|
||||
}
|
||||
PHYSFS_close(handle);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue