#986259 nntp.c: close the file pointer "in" before returning

Package:
src:nn
Source:
nn
Submitter:
Bjarni Ingi Gislason
Date:
2021-04-02 00:00:03 UTC
Severity:
normal
Tags:
#986259#5
Date:
2021-04-01 23:58:13 UTC
From:
To:
Dear Maintainer,

  The compiler option "-fanalyzer" shows:

nntp.c:1726:9: warning: leak of FILE 'in' [CWE-775] [-Wanalyzer-file-leak]
 1726 |  return 1;
      |         ^
...
    | 1716 |     FILE           *in = fopen(temp_file, "r");

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
---
 nntp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/nntp.c b/nntp.c
index 66064b6..07d7420 100644
--- a/nntp.c
+++ b/nntp.c
@@ -1723,8 +1723,10 @@ nntp_post(char *temp_file)
 	sprintf(delayed_msg, "Posting failed because we couldn't re-open file %s.", temp_file);
 	return 1;
     }
-    if (!is_connected && connect_server() < 0)
+    if (!is_connected && connect_server() < 0) {
+	fclose(in);
 	return 1;
+    }

     switch (n = ask_server("POST")) {
 	case CONT_POST: