[leafnode-list] Re: applyfilter failure malloc(16384) failed: Space for article

Matthias Andree matthias.andree at gmx.de
Wed Dec 15 13:40:30 CET 2010


Paul Brooks schrieb am 2010-12-14:

> 
> I'm running leafnode-2.0.0.alpha20081229a, using applyfilter I came across this error
> malloc(16384) failed: Space for article

Hi Paul,

sorry for the trouble, and congratulations on finding a memory leak!

The attached patch should fix that problem.  Apply it to your leafnode
source, then recompile and reinstall and let me know if it solves the
problem.  It does for me.  (Thanks to valgrind it was very easy to
find the culprit.)

Hope that helps & best regards
Matthias
-------------- next part --------------
commit ab4f1f7f8d2a143a452c0596e2c92d2df224be01
Author: Matthias Andree <matthias.andree at gmx.de>
Date:   Wed Dec 15 13:35:45 2010 +0100

    Plug memory leak in applyfilter().
    
    Reported 2010-12-14 by Paul Brooks through the mailing list.
    Analyzed with valgrind.

diff --git a/applyfilter.c b/applyfilter.c
index 3191cda..bfacaca 100644
--- a/applyfilter.c
+++ b/applyfilter.c
@@ -71,14 +71,12 @@ static int applyfilter(const char *name, struct newsgroup *g,
 	unsigned long *kept, unsigned long *deleted)
 {
     static size_t lsize = MAXHEADERSIZE + 1;
-    static char *l;
+    char *l;
     struct stat st;
     int score, fd;
     struct utimbuf u;
     unsigned long n;
 
-    l = (char *)critmalloc(lsize, "Space for article");
-
     if (stat(name, &st)) {
 	ln_log(LNLOG_SNOTICE, LNLOG_CARTICLE,
 		"cannot stat file \"%s\" in newsgroup %s: %m",
@@ -97,6 +95,8 @@ static int applyfilter(const char *name, struct newsgroup *g,
 	return 0;
     }
 
+    l = (char *)critmalloc(lsize, "Space for article");
+
     if((fd = open(name, O_RDONLY)) >= 0)
     {
 	int ret;
@@ -167,6 +167,9 @@ static int applyfilter(const char *name, struct newsgroup *g,
 	ln_log(LNLOG_SERR, LNLOG_CARTICLE,
 		"could not open file \"%s\" in newsgroup %s\n",
 		name, g->name);
+
+    free(l);
+
     return 0;
 }
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://krusty.dt.e-technik.tu-dortmund.de/pipermail/leafnode-list/attachments/20101215/338121be/attachment.pgp>


More information about the leafnode-list mailing list