[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[leafnode-list] [PATCH] huge 1.9.10 memory leak is now fixed



Lloyd Zusman <ljz@xxxxxxxxxx> writes:

> [ ... ]
> 
> Everything works fine with one exception: the leafnode process stays
> around and consumes ever-increasing amounts of memory ... after a few
> hours it's holding on to more than 60 megabytes.  [ ... ]

I debugged the 1.9.10 version and I found the memory leak: in
`activutil.c' there's the following call: `free( active )'.  However,
this `active' variable points to a list, each of whose members contain
string fields that were previously intialized via `strdup()'.
Therefore, every time the `active' list is reallocated, all the old
strdup-ed strings still are taking up memory.

I wrote a `freeactive()' routine which replaces the `free( active )'
call, and now the memory leak is gone.

Here's the patch:

*** activutil.c.orig	Mon Feb  7 15:04:38 2000
--- activutil.c	Sat Feb 12 11:46:45 2000
***************
*** 214,219 ****
--- 214,245 ----
  }
  
  /*
+  * free the 'active' list - this is needed instead of simply doing
+  * a free( active ) because the 'name' and 'desc' fields of the
+  * 'newsgroups' structure are filled by means of strdup().
+  */
+ void freeactive( void ) {
+ 
+     struct newsgroup * g;
+ 
+     if ( active == NULL ) {
+         return;
+     }
+ 
+     g = active;
+ 
+     while ( g->name ) {
+         free( g->name );
+ 	if ( g->desc ) {
+ 	    free( g->desc );
+ 	}
+ 	g++;
+     }
+ 
+     free( active );
+ }
+ 
+ /*
   * read active file into memory
   */
  void readactive( void ) {
***************
*** 225,231 ****
      struct newsgroup * g;
  
      if ( active ) {
! 	free( active );
  	active = NULL;
      }
  
--- 251,257 ----
      struct newsgroup * g;
  
      if ( active ) {
!         freeactive();
  	active = NULL;
      }
  
***************
*** 250,255 ****
--- 276,282 ----
      }
      else {
       	syslog( LOG_ERR, "unable to open %s: %m", s );
+ 	free(buf);
  	return;
      }
  
*** leafnode.h.orig	Sat Feb 12 11:43:00 2000
--- leafnode.h	Sat Feb 12 11:43:13 2000
***************
*** 92,97 ****
--- 92,98 ----
  void readactive( void );
  void writeactive( void );
  void fakeactive( void );
+ void freeactive( void );
  
  extern struct newsgroup * active;
  


-- 
 Lloyd Zusman
 ljz@xxxxxxxxxx

-- 
leafnode-list@xxxxxxxxxxxxxxxxxxxxxxxxxxxx -- mailing list for leafnode
To unsubscribe, send mail with "unsubscribe" in the subject to the list