win32-name-event-objects-20040228
authorJeffrey Altman <jaltman@mit.edu>
Sun, 29 Feb 2004 02:38:26 +0000 (02:38 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Sun, 29 Feb 2004 02:38:26 +0000 (02:38 +0000)
This is a very bad leak of Event Objects.  Name all of our event objects
in an attempt to identify the source of the leak.  Apparently, the leak
is not coming from any Event Objects we are creating directly.

Did find a misallocation of event objects in the smb code for the
initial session object.  Fixed.

src/WINNT/afsadmsvr/TaAfsAdmSvrCallback.cpp
src/WINNT/afsd/NTMakefile
src/WINNT/afsd/afsd_flushvol.c
src/WINNT/afsd/afsd_service.c
src/WINNT/afsd/smb.c
src/WINNT/afssvrmgr/alert.cpp
src/WINNT/bosctlsvc/bosctlsvc.c
src/WINNT/pthread/pthread.c

index 54431d1..2c7df7d 100644 (file)
@@ -54,7 +54,7 @@ void AfsAdmSvr_CallbackManager (void)
    AfsAdmSvr_Enter();
    if ((++l.cManagers) == 1)
       {
-      l.heCallback = CreateEvent (NULL, TRUE, FALSE, NULL);
+      l.heCallback = CreateEvent (NULL, TRUE, FALSE, TEXT("AfsAdmSvr_CallbackManager Event"));
       l.pListCallbacks = New (HASHLIST);
       }
    AfsAdmSvr_Leave();
index adec9be..a27894d 100644 (file)
@@ -308,7 +308,6 @@ AFSD_EXELIBS =\
        $(DESTDIR)\lib\afs\mtafsint.lib \
        $(DESTDIR)\lib\libafsconf.lib \
        $(DESTDIR)\lib\afs\afsreg.lib \
-       $(DESTDIR)\lib\libosi.lib \
        rpcrt4.lib \
        user32.lib \
     Dbghelp.lib
index 4ba3971..d0dce41 100644 (file)
@@ -399,24 +399,34 @@ PowerNotificationThreadCreate()
 {
        BOOL    bSuccess = FALSE;
        DWORD   dwThreadId = 0;
+    char    eventName[MAX_PATH];
        
        do 
        {
                // create power event notification event
                // bManualReset=TRUE, bInitialState=FALSE
-               gThreadInfo.hEventPowerEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+               gThreadInfo.hEventPowerEvent = CreateEvent(NULL, TRUE, FALSE, 
+                                                   TEXT("afsd_flushvol_EventPowerEvent"));
+        if ( GetLastError() == ERROR_ALREADY_EXISTS )
+            afsi_log("Event Object Already Exists: %s", eventName);
                if (gThreadInfo.hEventPowerEvent == NULL)
                        break;                  
 
                // create mainline resume event
                // bManualReset=FALSE, bInitialState=FALSE
-               gThreadInfo.hEventResumeMain = CreateEvent(NULL, FALSE, FALSE, NULL);
+               gThreadInfo.hEventResumeMain = CreateEvent(NULL, FALSE, FALSE, 
+                                                   TEXT("afsd_flushvol_EventResumeMain"));
+        if ( GetLastError() == ERROR_ALREADY_EXISTS )
+            afsi_log("Event Object Already Exists: %s", eventName);
                if (gThreadInfo.hEventResumeMain == NULL)
                        break;                  
 
                // create thread terminate event
                // bManualReset=FALSE, bInitialState=FALSE
-               gThreadInfo.hEventTerminate = CreateEvent(NULL, FALSE, FALSE, NULL);
+               gThreadInfo.hEventTerminate = CreateEvent(NULL, FALSE, FALSE, 
+                                                  TEXT("afsd_flushvol_EventTerminate"));
+        if ( GetLastError() == ERROR_ALREADY_EXISTS )
+            afsi_log("Event Object Already Exists: %s", eventName);
                if (gThreadInfo.hEventTerminate == NULL)
                        break;                  
 
index 6ee75a5..7dcb4a2 100644 (file)
@@ -327,7 +327,9 @@ void afsd_Main(DWORD argc, LPTSTR *argv)
 
        GlobalStatus = 0;
 
-       WaitToTerminate = CreateEvent(NULL, TRUE, FALSE, NULL);
+       WaitToTerminate = CreateEvent(NULL, TRUE, FALSE, TEXT("afsd_service_WaitToTerminate"));
+    if ( GetLastError() == ERROR_ALREADY_EXISTS )
+        afsi_log("Event Object Already Exists: %s", TEXT("afsd_service_WaitToTerminate"));
 
 #ifndef NOTSERVICE
        StatusHandle = RegisterServiceCtrlHandlerEx(AFS_DAEMON_SERVICE_NAME,
index dfac000..2f1e971 100644 (file)
@@ -985,30 +985,34 @@ retry:
                if (fid == fidp->fid) {
                        if (newFid) {
                                fid++;
-                                if (fid == 0) fid = 1;
-                                goto retry;
-                        }
+                if (fid == 0) fid = 1;
+                goto retry;
+            }
                        fidp->refCount++;
-                       break;
+            break;
                }
-        }
-        if (!fidp && (flags & SMB_FLAG_CREATE)) {
+    }
+    if (!fidp && (flags & SMB_FLAG_CREATE)) {
+        char eventName[MAX_PATH];
+        sprintf(eventName,"fid_t event fid=%d", fid);
                fidp = malloc(sizeof(*fidp));
-                memset(fidp, 0, sizeof(*fidp));
+        memset(fidp, 0, sizeof(*fidp));
                osi_QAdd((osi_queue_t **)&vcp->fidsp, &fidp->q);
-                fidp->refCount = 1;
-                fidp->vcp = vcp;
-                lock_InitializeMutex(&fidp->mx, "fid_t mutex");
-                fidp->fid = fid;
+        fidp->refCount = 1;
+        fidp->vcp = vcp;
+        lock_InitializeMutex(&fidp->mx, "fid_t mutex");
+        fidp->fid = fid;
                fidp->curr_chunk = fidp->prev_chunk = -2;
-               fidp->raw_write_event = thrd_CreateEvent(NULL, FALSE, TRUE, NULL);
-                if (newFid) {
+               fidp->raw_write_event = thrd_CreateEvent(NULL, FALSE, TRUE, eventName);
+        if ( GetLastError() == ERROR_ALREADY_EXISTS )
+            afsi_log("Event Object Already Exists: %s", eventName);
+        if (newFid) {
                        vcp->fidCounter = fid+1;
-                        if (vcp->fidCounter == 0) vcp->fidCounter = 1;
-                }
+            if (vcp->fidCounter == 0) vcp->fidCounter = 1;
         }
-        lock_ReleaseWrite(&smb_rctLock);
-        return fidp;
+    }
+    lock_ReleaseWrite(&smb_rctLock);
+    return fidp;
 }
 
 void smb_ReleaseFID(smb_fid_t *fidp)
@@ -1624,7 +1628,7 @@ unsigned int smb_GetSMBParm(smb_packet_t *smbp, int parm)
 
        if (parm >= parmCount) {
 #ifndef DJGPP
-               HANDLE h;
+        HANDLE h;
                char *ptbuf[1];
                char s[100];
                h = RegisterEventSource(NULL, AFS_DAEMON_EVENT_NAME);
@@ -6145,9 +6149,13 @@ void smb_Server(VOID *parmp)
                        /* Special handling for Write Raw */
                        raw_write_cont_t rwc;
                        EVENT_HANDLE rwevent;
-                       smb_DispatchPacket(vcp, bufp, outbufp, ncbp, &rwc);
+            char eventName[MAX_PATH];
+            
+            smb_DispatchPacket(vcp, bufp, outbufp, ncbp, &rwc);
                        if (rwc.code == 0) {
-                               rwevent = thrd_CreateEvent(NULL, FALSE, FALSE, NULL);
+                               rwevent = thrd_CreateEvent(NULL, FALSE, FALSE, TEXT("smb_Server() rwevent"));
+                if ( GetLastError() == ERROR_ALREADY_EXISTS )
+                    afsi_log("Event Object Already Exists: %s", eventName);
                                ncbp->ncb_command = NCBRECV | ASYNCH;
                                ncbp->ncb_lsn = (unsigned char) vcp->lsn;
                                ncbp->ncb_lana_num = vcp->lana;
@@ -6159,14 +6167,12 @@ void smb_Server(VOID *parmp)
 #else
                                Netbios(ncbp, dos_ncb);
 #endif /* !DJGPP */
-                               rcode = thrd_WaitForSingleObject_Event(rwevent,
-                                                                 RAWTIMEOUT);
+                               rcode = thrd_WaitForSingleObject_Event(rwevent, RAWTIMEOUT);
                                thrd_CloseHandle(rwevent);
                        }
                        thrd_SetEvent(SessionEvents[idx_session]);
                        if (rwc.code == 0)
-                               smb_CompleteWriteRaw(vcp, bufp, outbufp, ncbp,
-                                                    &rwc);
+                               smb_CompleteWriteRaw(vcp, bufp, outbufp, ncbp, &rwc);
                } else if (smbp->com == 0xa0) { 
                         /* 
                         * Serialize the handling for NT Transact 
@@ -6231,15 +6237,25 @@ void InitNCBslot(int idx)
        struct smb_packet *bufp;
        EVENT_HANDLE retHandle;
        int i;
+    char eventName[MAX_PATH];
 
     osi_assert( idx < (sizeof(NCBs) / sizeof(NCBs[0])) );
 
        NCBs[idx] = GetNCB();
-       NCBavails[idx] = thrd_CreateEvent(NULL, FALSE, TRUE, NULL);
+    sprintf(eventName,"NCBavails[%d]", idx);
+       NCBavails[idx] = thrd_CreateEvent(NULL, FALSE, TRUE, eventName);
+    if ( GetLastError() == ERROR_ALREADY_EXISTS )
+        afsi_log("Event Object Already Exists: %s", eventName);
 #ifndef DJGPP
-       NCBevents[idx] = thrd_CreateEvent(NULL, TRUE, FALSE, NULL);
+    sprintf(eventName,"NCBevents[%d]", idx);
+       NCBevents[idx] = thrd_CreateEvent(NULL, TRUE, FALSE, eventName);
+    if ( GetLastError() == ERROR_ALREADY_EXISTS )
+        afsi_log("Event Object Already Exists: %s", eventName);
 #endif /* !DJGPP */
-       retHandle = thrd_CreateEvent(NULL, FALSE, FALSE, NULL);
+    sprintf(eventName,"NCBReturns[0<=i<smb_NumServerThreads][%d]", idx);
+       retHandle = thrd_CreateEvent(NULL, FALSE, FALSE, eventName);
+    if ( GetLastError() == ERROR_ALREADY_EXISTS )
+        afsi_log("Event Object Already Exists: %s", eventName);
        for (i=0; i<smb_NumServerThreads; i++)
                NCBreturns[i][idx] = retHandle;
        bufp = GetPacket();
@@ -6414,6 +6430,7 @@ void smb_Listener(void *parmp)
                
                if (i == numSessions) {
                        /* Add new NCB for new session */
+            char eventName[MAX_PATH];
 
             osi_Log1(afsd_logp, "smb_Listener creating new session %d", i);
 
@@ -6424,7 +6441,10 @@ void smb_Listener(void *parmp)
                        for (j = 0; j < smb_NumServerThreads; j++)
                                thrd_SetEvent(NCBreturns[j][0]);
                        /* Also add new session event */
-                       SessionEvents[i] = thrd_CreateEvent(NULL, FALSE, TRUE, NULL);
+            sprintf(eventName, "SessionEvents[%d]", i);
+            SessionEvents[i] = thrd_CreateEvent(NULL, FALSE, TRUE, eventName);
+            if ( GetLastError() == ERROR_ALREADY_EXISTS )
+                afsi_log("Event Object Already Exists: %s", eventName);
                        numSessions++;
             afsi_log("increasing numNCBs [ %d ] numSessions [ %d ]", numNCBs, numSessions);
                        thrd_SetEvent(SessionEvents[0]);
@@ -6688,6 +6708,8 @@ void smb_Init(osi_log_t *logp, char *snamep, int useV3, int LANadapt,
     int npar, seg, sel;
     dos_ptr rawBuf;
 #endif /* DJGPP */
+    EVENT_HANDLE retHandle;
+    char eventName[MAX_PATH];
 
 #ifndef DJGPP
        smb_MBfunc = aMBfunc;
@@ -6796,15 +6818,28 @@ void smb_Init(osi_log_t *logp, char *snamep, int useV3, int LANadapt,
 
        /* Initialize listener and server structures */
        memset(dead_sessions, 0, sizeof(dead_sessions));
-       SessionEvents[0] = thrd_CreateEvent(NULL, FALSE, FALSE, NULL);
+    sprintf(eventName, "SessionEvents[0]");
+       SessionEvents[0] = thrd_CreateEvent(NULL, FALSE, FALSE, eventName);
+    if ( GetLastError() == ERROR_ALREADY_EXISTS )
+        afsi_log("Event Object Already Exists: %s", eventName);
        numSessions = 1;
        smb_NumServerThreads = nThreads;
-       NCBavails[0] = thrd_CreateEvent(NULL, FALSE, FALSE, NULL);
-       NCBevents[0] = thrd_CreateEvent(NULL, FALSE, FALSE, NULL);
+    sprintf(eventName, "NCBavails[0]");
+       NCBavails[0] = thrd_CreateEvent(NULL, FALSE, FALSE, eventName);
+    if ( GetLastError() == ERROR_ALREADY_EXISTS )
+        afsi_log("Event Object Already Exists: %s", eventName);
+    sprintf(eventName, "NCBevents[0]");
+       NCBevents[0] = thrd_CreateEvent(NULL, FALSE, FALSE, eventName);
+    if ( GetLastError() == ERROR_ALREADY_EXISTS )
+        afsi_log("Event Object Already Exists: %s", eventName);
        NCBreturns = malloc(nThreads * sizeof(EVENT_HANDLE *));
-       for (i = 0; i < nThreads; i++) {
+    sprintf(eventName, "NCBreturns[0<=i<smb_NumServerThreads][0]");
+    retHandle = thrd_CreateEvent(NULL, FALSE, FALSE, eventName);
+    if ( GetLastError() == ERROR_ALREADY_EXISTS )
+        afsi_log("Event Object Already Exists: %s", eventName);
+       for (i = 0; i < smb_NumServerThreads; i++) {
                NCBreturns[i] = malloc(NCBmax * sizeof(EVENT_HANDLE));
-               NCBreturns[i][0] = thrd_CreateEvent(NULL, FALSE, FALSE, NULL);
+               NCBreturns[i][0] = retHandle;
        }
        for (i = 1; i <= nThreads; i++)
                InitNCBslot(i);
index a7b92bd..597db4c 100644 (file)
@@ -712,7 +712,7 @@ BOOL Alert_StartScout (ULONG *pStatus)
 {
    if (hScout == 0)  // create scout?
       {
-      heScoutWakeup = CreateEvent (NULL, FALSE, FALSE, NULL);
+      heScoutWakeup = CreateEvent (NULL, FALSE, FALSE, TEXT("AfsSvrMgr Alert Scout Wakeup"));
 
       DWORD dwThreadID;
       if ((hScout = CreateThread (NULL, 0,
index 6188cbc..ae20e2c 100644 (file)
@@ -233,14 +233,14 @@ BosCtlMain(DWORD argc, LPTSTR *argv)
     if ((bosCtlEvent[BOS_STOP_EVENT] = CreateEvent(NULL,
                                                   FALSE /* manual reset */,
                                                   FALSE /* initial state */,
-                                                  NULL)) == NULL) {
+                                                  TEXT("BosCtlSvc Stop Event"))) == NULL) {
        status = GetLastError();
     }
 
     if ((bosCtlEvent[BOS_EXIT_EVENT] = CreateEvent(NULL,
                                                   FALSE /* manual reset */,
                                                   FALSE /* initial state */,
-                                                  NULL)) == NULL) {
+                                                  TEXT("BosCtlSvc Exit Event"))) == NULL) {
        status = GetLastError();
     }
 
index 4c72ab6..0c8918d 100644 (file)
@@ -587,11 +587,15 @@ static DWORD WINAPI terminate_thread_routine(LPVOID param) {
 
 
 static void pthread_sync_terminate_thread(void) {
+
     (pthread_cache_done || pthread_once(&pthread_cache_once, create_once));
 
     if (terminate_thread_handle == INVALID_HANDLE_VALUE) {
+        CHAR eventName[MAX_PATH];
+        static eventCount = 0;
+        sprintf(eventName, "pthread terminate thread %d", eventCount++);
        terminate_thread_wakeup_event = CreateEvent((LPSECURITY_ATTRIBUTES) 0,
-                               TRUE, FALSE, (LPCTSTR) 0);
+                               TRUE, FALSE, (LPCTSTR) eventName);
        terminate_thread_handle = CreateThread((LPSECURITY_ATTRIBUTES) 0, 0, 
                                terminate_thread_routine, (LPVOID) 0, 0, 
                                &terminate_thread_id);
@@ -711,8 +715,11 @@ static cond_waiters_t *get_waiter() {
     if (queue_IsEmpty(&waiter_cache)) {
         new = (cond_waiters_t *) malloc(sizeof(cond_waiters_t));
        if (new != NULL) {
+        CHAR eventName[MAX_PATH];
+        static eventCount = 0;
+        sprintf(eventName, "cond_waiters_t %d", eventCount++);
            new->event = CreateEvent((LPSECURITY_ATTRIBUTES) 0, FALSE,
-                                    FALSE, (LPCTSTR) 0);
+                                    FALSE, (LPCTSTR) eventName);
            if (new->event == NULL) {
                free(new);
                new = NULL;