W3C home > Mailing lists > Public > www-lib@w3.org > January to March 2003

RE: is there a memory leak?

From: Tim Serong <tim.serong@conceiva.com>
Date: Wed, 26 Mar 2003 13:59:56 +1100
Message-ID: <8501919721C3DE4C81BCA22846B08721BC1D@lazarus.conceiva.com>
To: "Tanmay Patwardhan" <tpthesis@hotmail.com>
Cc: <www-lib@w3.org>

On Saturday, 22 March 2003 08:34, Tanmay Patwardhan wrote:
> Hi,
> In my program using libwww, using purify on the application, 
> it reported a 
> few mem. leaks all at the following piece of code:
> ...
> I am deleting the profile at the end of the program as:
> HTProfile_delete();

I've recently found a number of memory leaks, for which I have

* Timers, Net objects and Alerts are not freed in HTLibTerminate(),
which at the very least will leave a few lists in existence.
Additionally there is at least one Atom left lying around after
HTLibTerminate().  These issues can be fixed in HTLibTerminate() as

- Add a call to HTNet_deleteAll() after the call to HTNet_killAll().
- Add a call to HTTimer_deleteAll() after the call to
- Add a call to HTAlert_deleteAll() after the call to
- Move the call to HTAtom_deleteAll() to the very end of
HTLibTerminate() - if this is called earlier, at least one of the other
*deleteAll functions actually allocates an Atom again, which is not
subsequently freed.

* All sorts of things are not freed in HTProfile_delete().  Here's what
I've done to fix this:

PUBLIC void HTProfile_delete (void)
  if (!preemptive) HTEventTerminate();
  if (HTLib_isInitialized()) {
      /* Get rid of any remaining events */
      /* Cleanup for HTNetInit() */
      /* Cleanup for HTTransportInit() */	
      /* Cleanup for HTAAInit() */
      /* Cleanup for HTMIMEInit() */
      /* Cleanup for HTIconInit() */
      /* Delete the rull allocated in HTIconInit() */
       * Original code continues from here...

I do not know if the deallocation I have added is in the "best" places,
or in the best order, however it works for me.  AFAICT I now have no
memory leaks when doing HTTP requests with a NoCacheClient.  I still
have some memory leaks after making FTP requests, but I have not looked
at these yet.

* After making an FTP request you'll get an access violation in
HTChannel_deleteAll() when calling HTProfile_delete().  This can be
fixed by applying a patch from Peter Stamfest at
http://lists.w3.org/Archives/Public/www-lib/2000JulSep/0241.html (This
won't be the source of your problem, but it's worth applying the patch

> Is there anything I am missing? This happens wierdly only the 
> second time I 
> use the library in my app, is that means anything!

I'm not sure about that issue, but if you initialize the library only
once when your application starts, and clean up at the very end of your
program, I would guess the problem will go away.


Tim Serong
Received on Tuesday, 25 March 2003 21:59:35 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:33:55 UTC