]> granicus.if.org Git - neomutt/commitdiff
nntp: fix resource leak
authorRichard Russon <rich@flatcap.org>
Tue, 18 Oct 2016 15:40:18 +0000 (16:40 +0100)
committerRichard Russon <rich@flatcap.org>
Tue, 18 Oct 2016 16:02:42 +0000 (17:02 +0100)
Every $nntp_poll seconds, NNTP checks the file $newsrc
Unfortunately, it didn't release the file handle afterwards.

After a day's use, this would leak 1440 file handles leading most users
to the error "Too many open files".

Fixes: #204
newsrc.c

index a987602861af53b932c30f209546ffb3cf520210..ad8255f03e608966a41aab4509f025b422c15e93 100644 (file)
--- a/newsrc.c
+++ b/newsrc.c
@@ -128,9 +128,17 @@ int nntp_newsrc_parse (NNTP_SERVER *nserv)
   char *line;
   struct stat sb;
 
-  /* if file doesn't exist, create it */
-  nserv->newsrc_fp = safe_fopen (nserv->newsrc_file, "a");
-  safe_fclose (&nserv->newsrc_fp);
+  if (nserv->newsrc_fp)
+  {
+    /* if we already have a handle, close it and reopen */
+    safe_fclose (&nserv->newsrc_fp);
+  }
+  else
+  {
+    /* if file doesn't exist, create it */
+    nserv->newsrc_fp = safe_fopen (nserv->newsrc_file, "a");
+    safe_fclose (&nserv->newsrc_fp);
+  }
 
   /* open .newsrc */
   nserv->newsrc_fp = safe_fopen (nserv->newsrc_file, "r");