* ARGUMENTS:
* SearchContext = Pointer to search context
* RETURNS:
- * Pointer to address file, NULL if none was found
+ * Pointer to referenced address file, NULL if none was found
*/
PADDRESS_FILE AddrSearchNext(
PAF_SEARCH SearchContext)
KIRQL OldIrql;
PADDRESS_FILE Current = NULL;
BOOLEAN Found = FALSE;
+ PADDRESS_FILE StartingAddrFile;
TcpipAcquireSpinLock(&AddressFileListLock, &OldIrql);
return NULL;
}
- /* Remove the extra reference we added to keep this address file in memory */
- DereferenceObject(CONTAINING_RECORD(SearchContext->Next, ADDRESS_FILE, ListEntry));
+ /* Save this pointer so we can dereference it later */
+ StartingAddrFile = CONTAINING_RECORD(SearchContext->Next, ADDRESS_FILE, ListEntry);
CurrentEntry = SearchContext->Next;
/* Reference the next address file to prevent the link from disappearing behind our back */
ReferenceObject(CONTAINING_RECORD(SearchContext->Next, ADDRESS_FILE, ListEntry));
}
+
+ /* Reference the returned address file before dereferencing the starting
+ * address file because it may be that Current == StartingAddrFile */
+ ReferenceObject(Current);
}
else
Current = NULL;
+ DereferenceObject(StartingAddrFile);
+
TcpipReleaseSpinLock(&AddressFileListLock, OldIrql);
return Current;