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
diff --git a/openbsc/src/gprs/gtphub_main.c b/openbsc/src/gprs/gtphub_main.c
index f56c446..bfb0a3d 100644
--- a/openbsc/src/gprs/gtphub_main.c
+++ b/openbsc/src/gprs/gtphub_main.c
@@ -166,8 +166,10 @@
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);