cleaning up HostTable

As I said before, I'm using libwww in a somewhat strange way.

I have a module that can be called to process HTML pages. This module
initialize the library, use it and then release it (by calling
HTLibTerminate).

The main application can call the module again and reuse it. So, if the
HTLibTerminate
doesn't correctly clean up the global data structures (or at least leave
them in a
consistent state) libwww will crash at the next attempt.

So, I'm not completely sure on how this happen (or better, why it does not
happen on every
page), but I got this crash when downloading a specific page multiple times.
I found out
the channels were deleted (HTLibTerminate calls HTChannel_deleteAll), but
the HTHost objects
referencing them were not cleaned up. So, I added an HTHost_deleteAll and
called it before
HTChannel_delete all. Maybe this is too much, but it works.

-- Raffaele

--------------------------- 8< CUT HERE
>8 ----------------------------------
cvs diff HTLib.c HTHost.html HTHost.c (in directory
c:\SOFTWAREDEV\LIBWWW\Library\src)
Index: HTLib.c
===================================================================
RCS file: /sources/public/libwww/Library/src/HTLib.c,v
retrieving revision 2.15
diff -r2.15 HTLib.c
190a191
>     HTHost_deleteAll();  /* Delete remaining hosts */
Index: HTHost.html
===================================================================
RCS file: /sources/public/libwww/Library/src/HTHost.html,v
retrieving revision 2.27
diff -r2.27 HTHost.html
79a80,87
>   Delete the Host table
> </H3>
> <P>
> Cleanup and delete the host table.
> <PRE>
> extern void HTHost_deleteAll (void);
> </PRE>
> <H3>
Index: HTHost.c
===================================================================
RCS file: /sources/public/libwww/Library/src/HTHost.c,v
retrieving revision 2.61
diff -r2.61 HTHost.c
451a452,477
> ** Cleanup the host list
> */
> PUBLIC void HTHost_deleteAll (void)
> {
>     HTList * list;
>     HTHost * host;
>     int i;
>
>     if (!HostTable)
>  return;
>
>     for (i=0; i < HOST_HASH_SIZE; i++) {
>  list = HostTable[i];
>  if (!list) continue;
>
>  while ((host = (HTHost *) HTList_removeFirstObject(list)) != NULL)
>      free_object(host);
>
>  HTList_delete(list);
>     }
>
>     HT_FREE(HostTable);
>     HostTable = NULL;
> }
>
> /*
1056a1083
>       host->channel = NULL;
1075c1102
<                 if (HTChannel_delete(host->channel, status))
---
>                 if (HTChannel_delete(host->channel, status)) {
1077c1104,1105
<
---
>       host->channel = NULL;
>                 }
1109a1138
>  host->lock = HTList_firstObject(host->pending);

Received on Thursday, 25 March 1999 21:13:46 UTC