RE: is there a memory leak?

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
solutions:

* 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
follows:

- Add a call to HTNet_deleteAll() after the call to HTNet_killAll().
- Add a call to HTTimer_deleteAll() after the call to
HTChannel_deleteAll().
- Add a call to HTAlert_deleteAll() after the call to
HTUTree_deleteAll().
- 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 */
    HTEventList_unregisterAll();
      /* Cleanup for HTNetInit() */
    HTNetCall_deleteBeforeAll(HTNet_before());
    HTNetCall_deleteAfterAll(HTNet_after());
      /* Cleanup for HTTransportInit() */	
    HTTransport_deleteAll();
      /* Cleanup for HTAAInit() */
    HTAA_deleteAllModules();
      /* Cleanup for HTMIMEInit() */
    HTHeader_deleteAll();
      /* Cleanup for HTIconInit() */
    HTIcon_deleteAll();
      /* Delete the rull allocated in HTIconInit() */
    HTRule_deleteAll(HTRule_global());
      /* 
       * 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
anyway)

> 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.

Regards,

Tim Serong
-- 
tim.serong@conceiva.com
http://www.conceiva.com

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