From 8bd8f371d73fafddb409cdcc98467632dc111125 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Sat, 29 Dec 2012 00:44:27 -0500 Subject: [PATCH] Windows: AFSSetFileLinkInfo() DirOpenReferenceCount handling AFSSetFileLinkInfo() would leak a DirOpenReferenceCount when pNewTargetDirEntry is not NULL upon exit. It also did not properly handle a STATUS_REPARSE response from AFSNotifyHardLink(). The AFSInsertDirectoryNode() call should not be performed when the result is STATUS_REPARSE since that means the entry already exists. Change-Id: Ibbf497cb4c3c412e4f95cdffc6025f03f0e2ed8b Reviewed-on: http://gerrit.openafs.org/8857 Tested-by: BuildBot Reviewed-by: Jeffrey Altman Tested-by: Jeffrey Altman --- src/WINNT/afsrdr/kernel/lib/AFSFileInfo.cpp | 39 ++++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/WINNT/afsrdr/kernel/lib/AFSFileInfo.cpp b/src/WINNT/afsrdr/kernel/lib/AFSFileInfo.cpp index e083c82a7..786df07c6 100644 --- a/src/WINNT/afsrdr/kernel/lib/AFSFileInfo.cpp +++ b/src/WINNT/afsrdr/kernel/lib/AFSFileInfo.cpp @@ -2465,7 +2465,7 @@ AFSSetFileLinkInfo( IN PIRP Irp) "AFSSetFileLinkInfo Target %wZ exists DE %p Count %d, performing delete of target\n", &pTargetDirEntry->NameInformation.FileName, pTargetDirEntry, - pTargetDirEntry->DirOpenReferenceCount); + lCount); // // Pull the directory entry from the parent @@ -2498,7 +2498,8 @@ AFSSetFileLinkInfo( IN PIRP Irp) pFileLinkInfo->ReplaceIfExists, &pNewTargetDirEntry); - if( !NT_SUCCESS( ntStatus)) + if( ntStatus != STATUS_REPARSE && + !NT_SUCCESS( ntStatus)) { AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING, @@ -2511,9 +2512,13 @@ AFSSetFileLinkInfo( IN PIRP Irp) try_return( ntStatus); } - AFSInsertDirectoryNode( pTargetDcb->ObjectInformation, - pNewTargetDirEntry, - TRUE); + if ( ntStatus != STATUS_REPARSE) + { + + AFSInsertDirectoryNode( pTargetDcb->ObjectInformation, + pNewTargetDirEntry, + TRUE); + } // // Send notification for the target link file @@ -2552,6 +2557,10 @@ AFSSetFileLinkInfo( IN PIRP Irp) if( pTargetDirEntry != NULL) { + // + // Release DirOpenReferenceCount obtained above + // + lCount = InterlockedDecrement( &pTargetDirEntry->DirOpenReferenceCount); AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING, @@ -2565,6 +2574,26 @@ AFSSetFileLinkInfo( IN PIRP Irp) ASSERT( lCount >= 0); } + if( pNewTargetDirEntry != NULL) + { + + // + // Release DirOpenReferenceCount obtained from AFSNotifyHardLink + // + + lCount = InterlockedDecrement( &pNewTargetDirEntry->DirOpenReferenceCount); + + AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING, + AFS_TRACE_LEVEL_VERBOSE, + "AFSSetFileLinkInfo Decrement count on %wZ DE %p Ccb %p Cnt %d\n", + &pNewTargetDirEntry->NameInformation.FileName, + pNewTargetDirEntry, + pSrcCcb, + lCount); + + ASSERT( lCount >= 0); + } + if( bReleaseTargetDirLock) { -- 2.39.5