Skip to content
Tcl Source Code View Ticket
Login

View Ticket

leaking critical sections...

Closed / Works For Me731778ffffffffffffffffffffffffffffffffffCreated 24 years agoUpdated 22 years ago
Descriptionplain2003-05-03 10:08:29
The following critical sections are never deleted 
(not even during process detach) via 
DeleteCriticalSection:

from tclWinThrd.c: 

joinLock
initLock
masterLock

This may not be a complete list, I have not checked 
the rest of the Tcl/Tk source code.

JJM
mistachkinplain2003-05-03 17:11:10
Logged In: YES 
user_id=113501

This should be fixed by deleting the critical sections 
upon process detach (when the Tcl dll is being 
unloaded). It will probably have to be done either dead 
last in the finalization process or darn close to it.
kennykb Ticket [731778ffff]: 1 change [History diff]2003-05-06 18:39:00
andreas_kupries Ticket [731778ffff]: 1 change [History diff]2003-05-07 06:08:32
mistachkinplain2003-05-10 15:36:02
Logged In: YES 
user_id=113501

JeffH, I can help you fix this issue.  I have some ideas 
that I would like to run by you.
hobbsplain2003-07-17 06:25:27
Logged In: YES 
user_id=72656

any update on a patch for these?
dgp Ticket [731778ffff]: 1 change [History diff]2003-11-13 08:29:58
mistachkinplain2004-06-24 15:14:23
Logged In: YES 
user_id=113501


David, I believe you have fixed this bug?  By the way, looking 
at the code in TclFinalizeLock, are you sure it's safe to delete 
a critical section that you are currently holding?
mistachkinplain2004-06-24 15:53:21
Logged In: YES 
user_id=113501

from MSDN: 

DeleteCriticalSection

"... If a critical section is deleted while it is still owned, the 
state of the threads waiting for ownership of the deleted 
critical section is undefined."
davygrvyplain2004-06-24 16:39:59
Logged In: YES 
user_id=7549

The change went into the HEAD on 2004-04-22 and the 8.4 
branch on 2004-05-05

If deleting an owned CRITICAL_SECTION causes any bad stuff 
we can change it.  I haven't found any bad results from it.  
Right after this we're a dozen or so calls from hitting 
ExitProcess or DllMain exiting anyways.  I'm not too worried 
given that I can't find any bad stuff that it causes.

I could add a Tcl_MutexUnlock(initLock); before 
TclFinalizeLock if you want?
davygrvyplain2004-06-25 02:26:38
Logged In: YES 
user_id=7549

How's this?

RCS file: /cvsroot/tcl/tcl/win/tclWinThrd.c,v
retrieving revision 1.31
diff -c -r1.31 tclWinThrd.c
*** tclWinThrd.c22 Jun 2004 13:09:01 -00001.31
--- tclWinThrd.c24 Jun 2004 19:24:27 -0000
***************
*** 435,441 ****
  allocOnce = 0;
      }
  #endif
!     /* Destroy the critical section that we are holding. */
      DeleteCriticalSection(&initLock);
  }
  
--- 435,442 ----
  allocOnce = 0;
      }
  #endif
!     LeaveCriticalSection(&initLock);
!     /* Destroy the critical section that we were holding. */
      DeleteCriticalSection(&initLock);
  }

Just adding a leave before the destroy?
davygrvy Ticket [731778ffff]: 1 change [History diff]2004-10-27 03:48:44
davygrvyplain2004-10-28 03:57:10
Logged In: YES 
user_id=7549

committed to HEAD.
Log in (anonymous is fine) to add a comment.