INN commit: trunk/backends (ninpaths.c)

INN Commit rra at isc.org
Sun Jun 14 10:05:22 UTC 2015


    Date: Sunday, June 14, 2015 @ 03:05:22
  Author: iulius
Revision: 9892

Fix ninpaths memory leak

Realistically this isn't very likely to cause anyone any trouble.
However, fixing it reduces noise that might obscure more serious
problems.

Thanks to Richard Kettlewell for the patch.

Modified:
  trunk/backends/ninpaths.c

------------+
 ninpaths.c |   15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

Modified: ninpaths.c
===================================================================
--- ninpaths.c	2015-06-03 19:08:50 UTC (rev 9891)
+++ ninpaths.c	2015-06-14 10:05:22 UTC (rev 9892)
@@ -218,13 +218,13 @@
     long i, m, l;
     unsigned long st, et, at;
     long sit, tot;
-    struct nrec **n;
+    struct nrec **n = NULL;
     struct trec *t;
     char c[MAXHOST];
     char v[16];
 
     #define formerr(i) {\
-	fprintf(stderr, "dump file format error #%d\n", (i)); return -1; }
+        fprintf(stderr, "dump file format error #%d\n", (i)); goto error; }
 
     if (fscanf(f, "!!NINP %15s %lu %lu %ld %ld %lu\n",
 	       v, &st, &et, &sit, &tot, &at)!=6)
@@ -233,7 +233,7 @@
     n=calloc(sit, sizeof(struct nrec *));
     if (!n) {
 	fprintf(stderr, "error: out of memory\n");
-	return -1;
+        goto error;
     }
     for (i=0; i<sit; i++) {
 	if (fscanf(f, HOSTF " %ld ", c, &l)!=2) {
@@ -242,7 +242,7 @@
 	}
 	n[i]=hhost(c);
         if (!n[i])
-            return -1;
+            goto error;
         n[i]->sentto+=l;
     }
     if ((fscanf(f, HOSTF "\n", c)!=1) ||
@@ -254,7 +254,7 @@
 	while (fscanf(f, "%d!%d!%ld ", &a, &b, &l)==3) {
 	    t=tallyrec(n[a], n[b]);
 	    if (!t)
-                return -1;
+                goto error;
             t->tally+=l;
 	    ++m;
 	}
@@ -266,7 +266,7 @@
 		if (i<2)
 		    l=1;
 		if (!t)
-                    return -1;
+                    goto error;
                 t->tally+=l;
 		++m;
 	    }
@@ -298,6 +298,9 @@
 #endif
     free(n);
     return 0;
+error:
+    free(n);
+    return -1;
 }
 
 /* Read dump from a file. */



More information about the inn-committers mailing list