gtphub: Fix use after free on failure

Even if fclose fails the stream is inaccessible and the second fclose
might cause memory violation.

Linux manpage says:
Upon  successful  completion 0 is returned.  Otherwise, EOF is returned
and errno is set to indicate the error.  In either case any further
access (including another call to fclose()) to the stream results in
undefined behavior.

Fixes: CID#57958
This commit is contained in:
Holger Hans Peter Freyther 2016-01-23 10:28:09 +01:00
parent f9f44901a2
commit de76661cf3
1 changed files with 3 additions and 1 deletions

View File

@ -166,8 +166,10 @@ static uint8_t next_restart_count(const char *path)
goto failed_to_write;
if (fprintf(f, "%" PRIu8 "\n", counter) < 2)
goto failed_to_write;
if (fclose(f))
if (fclose(f)) {
f = NULL;
goto failed_to_write;
}
umask(umask_was);