Fix T81271: Fix crash in BLI_gzopen on Windows

Previously the return value of `ufopen` wasn't checked and if it failed,
`NULL` was passed into `fclose()` which resulted in a crash. This patch
avoids this by returning from `BLI_gzopen` when the file cannot be created.

Reviewed By: sebbas, iss

Differential Revision: https://developer.blender.org/D9576
This commit is contained in:
Robert Guetzkow 2020-11-16 13:04:23 +01:00
parent 7db42b8f2a
commit 8b815c7ce5
Notes: blender-bot 2023-02-14 11:29:52 +01:00
Referenced by issue #81271, Fluid: Crash with empty cache path
1 changed files with 6 additions and 1 deletions

View File

@ -357,7 +357,12 @@ void *BLI_gzopen(const char *filename, const char *mode)
/* xxx Creates file before transcribing the path */
if (mode[0] == 'w') {
fclose(ufopen(filename, "a"));
FILE *file = ufopen(filename, "a");
if (file == NULL) {
/* File couldn't be opened, e.g. due to permission error. */
return NULL;
}
fclose(file);
}
/* temporary #if until we update all libraries to 1.2.7