Re: HTEventList_newLoop memory leak

Stuart Myles wrote:

> However, my server leaks some memory each time it calls the
> HTEventList_newLoop function in step 2.  (I believe HTList_new
> is getting called somewhere).
> 
> If this is the right way to achieve what I want, how do I clean up the
> memory allocated during HTEventList_newLoop?  If this is not the
> right way to achieve this, what should I be doing?

Try this patch to see if that works better. I have also added a check
that the loop isn't already running.

-- 
Henrik Frystyk Nielsen, <frystyk@w3.org>
World Wide Web Consortium, MIT/LCS NE43-356
545 Technology Square, Cambridge MA 02139, USA
Index: HTEvtLst.c
===================================================================
RCS file: /sources/public/libwww/Library/src/HTEvtLst.c,v
retrieving revision 2.40
diff -c -r2.40 HTEvtLst.c
*** HTEvtLst.c	1999/06/23 18:00:53	2.40
--- HTEvtLst.c	1999/06/23 18:28:39
***************
*** 64,69 ****
--- 64,70 ----
  PRIVATE HTList * HashTable [HT_M_HASH_SIZE]; 
  PRIVATE HTList * EventOrderList = NULL;
  PRIVATE int HTEndLoop = 0;		       /* If !0 then exit event loop */
+ PRIVATE BOOL HTInLoop = NO;
  
  #ifdef WWW_WIN_ASYNC
  #define TIMEOUT	1 /* WM_TIMER id */
***************
*** 325,338 ****
      return HT_OK;
  }
  
! PUBLIC BOOL EventOrder_deleteAll (void) 
  {
      HTList * cur = EventOrderList;
      EventOrder * pres;
!     HTTRACE(THD_TRACE, "EventOrder.. all ordered events\n");
!     if (cur == NULL) return NO;
!     while ((pres = (EventOrder *) HTList_nextObject(cur)))
! 	HT_FREE(pres);
      HTList_delete(EventOrderList);
      EventOrderList = NULL;
      return YES;
--- 326,347 ----
      return HT_OK;
  }
  
! PRIVATE BOOL EventOrder_clearAll (void)
  {
      HTList * cur = EventOrderList;
      EventOrder * pres;
!     HTTRACE(THD_TRACE, "EventOrder.. Clearing all ordered events\n");
!     if (cur) {
! 	while ((pres = (EventOrder *) HTList_nextObject(cur)))
! 	    HT_FREE(pres);
! 	return YES;
!     }
!     return NO;
! }
! 
! PUBLIC BOOL EventOrder_deleteAll (void) 
! {
!     EventOrder_clearAll();
      HTList_delete(EventOrderList);
      EventOrderList = NULL;
      return YES;
***************
*** 630,637 ****
      ms_t now;
      SOCKET s;
      int status = HT_OK;
  
!     EventOrderList = HTList_new();	/* is kept around until EventOrder_deleteAll */
  
      /* Don't leave this loop until we leave the application */
      while (!HTEndLoop) {
--- 639,657 ----
      ms_t now;
      SOCKET s;
      int status = HT_OK;
+ 
+     /* Check that we don't have multiple loops started at once */
+     if (HTInLoop) {
+ 	HTTRACE(THD_TRACE, "Event Loop.. Already one loop running - exiting\n");
+ 	return HT_ERROR;
+     }
+     HTInLoop = YES;
  
!     /* Set up list of events - is kept around until EventOrder_deleteAll */
!     if (!EventOrderList)
! 	EventOrderList = HTList_new();
!     else
! 	EventOrder_clearAll();
  
      /* Don't leave this loop until we leave the application */
      while (!HTEndLoop) {
***************
*** 742,747 ****
--- 762,768 ----
      /* Reset HTEndLoop in case we want to start again */
   stop_loop:
      HTEndLoop = 0;
+     HTInLoop = NO;
      return status;
  #endif /* !WWW_WIN_ASYNC */
  }

Received on Wednesday, 23 June 1999 14:33:15 UTC