Windows: do not leak resource in AFSQueryDirectory
authorJeffrey Altman <jaltman@your-file-system.com>
Fri, 4 Nov 2011 12:40:03 +0000 (08:40 -0400)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Fri, 4 Nov 2011 22:38:53 +0000 (15:38 -0700)
Track whether or not the pFcb->NPFcb->Resource is held so
it can be released in all error paths.

Change-Id: I8c8bfb912329e8c11ac7857086412d85aa64fea6
Reviewed-on: http://gerrit.openafs.org/5804
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@secure-endpoints.com>
Tested-by: Jeffrey Altman <jaltman@secure-endpoints.com>

src/WINNT/afsrdr/kernel/lib/AFSDirControl.cpp

index cf7ec7b..5471bee 100644 (file)
@@ -141,6 +141,7 @@ AFSQueryDirectory( IN PIRP Irp)
     ULONG ulBytesConverted;
     AFSDirectoryCB *pDirEntry = NULL;
     BOOLEAN bReleaseMain = FALSE;
+    BOOLEAN bReleaseFcb = FALSE;
     ULONG ulTargetFileType = AFS_FILE_TYPE_UNKNOWN;
     AFSFileInfoCB       stFileInfo;
     BOOLEAN         bUseFileInfo = TRUE;
@@ -221,6 +222,8 @@ AFSQueryDirectory( IN PIRP Irp)
             AFSAcquireExcl( &pFcb->NPFcb->Resource,
                             TRUE);
 
+            bReleaseFcb = TRUE;
+
             //
             // Tell the service to prime the cache of the directory content
             //
@@ -231,8 +234,6 @@ AFSQueryDirectory( IN PIRP Irp)
             if( !NT_SUCCESS( ntStatus))
             {
 
-                AFSReleaseResource( &pFcb->NPFcb->Resource);
-
                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
                               AFS_TRACE_LEVEL_ERROR,
                               "AFSQueryDirectory Enumerate directory failure for parent %wZ Mask %wZ Status %08lX\n",
@@ -259,6 +260,8 @@ AFSQueryDirectory( IN PIRP Irp)
 
             AFSAcquireShared( &pFcb->NPFcb->Resource,
                               TRUE);
+
+            bReleaseFcb = TRUE;
         }
 
         //
@@ -336,6 +339,8 @@ AFSQueryDirectory( IN PIRP Irp)
 
         AFSReleaseResource( &pFcb->NPFcb->Resource);
 
+        bReleaseFcb = FALSE;
+
         //
         // Start processing the data
         //
@@ -973,6 +978,12 @@ try_exit:
             AFSReleaseResource( pFcb->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
         }
 
+        if ( bReleaseFcb)
+        {
+
+            AFSReleaseResource( &pFcb->NPFcb->Resource);
+        }
+
         if( pFcb != NULL)
         {