memory leak

Dan Deward dan at cmsconnect.com
Thu Mar 27 21:18:20 CET 2003


David,

Well, then speaking of memory leaks... it seems like wordhash_free has a
problem?  I think this code below should use the iterator to traverse the
list.

change this...

  wh_alloc_node *np, *nq;
  wh_alloc_str *sp, *sq;

  if (h == NULL)
    return;

  for (np = h->nodes; np; np = nq)
    {
      nq = np->next;
      xfree (np->buf);
      xfree (np);
    }

to maybe something like...

    hashnode_t *		p = NULL;
    hashnode_t *		q = NULL;
    
    if (h == NULL)
        return;

    for (p = h->iter_head; p != NULL; )
    {
      q = p->iter_next;

      xfree( p->key->text );
      word_free( p->key );
    	
	p = q; 
    }

And you may want to add some additional free'ing by changing this:

    xfree (h->bin);
    xfree (h);

to this...

    if( h->iter_head != NULL )
	xfree( h->iter_head );

    if( h->order != NULL )
	xfree( h->order );

    xfree( h->nodes );
    xfree (h->bin);
    xfree (h);

Hope this helps.

Dan


-----Original Message-----
From: David Relson [mailto:relson at osagesoftware.com] 
Sent: Thursday, March 27, 2003 3:07 PM
To: Dan Deward
Cc: bogofilter-dev
Subject: memory leak [was: debian.s390 problem]


At 02:54 PM 3/27/03, Dan Deward wrote:

>Hi,
>
>I noticed that the method that method word_new does one xmalloc, and 
>word_free does one xfree, but word_dup does two xmalloc's.  Wouldn't 
>this case a memory leak when word_free is used on a word that was 
>word_dup'ed? These three methods are in word.c
>
>Dan

Dan,

Good eye!  It _does_ look like you've found a problem.  Since bogofilter 
currently runs as needed, any memory allocation mistakes are cleaned up by 
the OS when it exits.  So, this flaw is not _presently_ a big 
problem.  However, it shouldn't be present.  Now, I have to figure out the 
best fix ...

Thanks for reporting it.

David





More information about the bogofilter-dev mailing list