Skip to content

Commit 9c22739

Browse files
committed
Fix memory leak. Fixes #701
1 parent c7acb36 commit 9c22739

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

packetWin7/npf/npf/Read.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ ULONG NPF_GetMetadata(
639639

640640
//-------------------------------------------------------------------
641641
_When_(AtDispatchLevel != FALSE, _IRQL_requires_(DISPATCH_LEVEL))
642-
VOID
642+
BOOLEAN
643643
NPF_TapExForEachOpen(
644644
_Inout_ POPEN_INSTANCE Open,
645645
_Inout_ PNPF_CAP_DATA pCapData,
@@ -802,7 +802,11 @@ NPF_DoTap(
802802
continue;
803803
}
804804
}
805-
NPF_TapExForEachOpen(pCapData->pOpen, pCapData, AtDispatchLevel);
805+
if (!NPF_TapExForEachOpen(pCapData->pOpen, pCapData, AtDispatchLevel))
806+
{
807+
// Didn't accept it. Clean up!
808+
NPF_ReturnCapData(pCapData);
809+
}
806810
}
807811

808812
// Now release/return the copies
@@ -1007,7 +1011,7 @@ NPF_CopyFromNetBufferToNBCopy(
10071011
}
10081012

10091013
_Use_decl_annotations_
1010-
VOID
1014+
BOOLEAN
10111015
NPF_TapExForEachOpen(
10121016
POPEN_INSTANCE Open,
10131017
PNPF_CAP_DATA pCapData,
@@ -1020,11 +1024,12 @@ NPF_TapExForEachOpen(
10201024
PNPF_NBL_COPY pNBLCopy = pNBCopy->pNBLCopy;
10211025
ULONG TotalPacketSize = pNBCopy->ulPacketSize;
10221026
ULONG fres = pCapData->ulCaplen;
1027+
BOOLEAN bEnqueued = FALSE;
10231028

10241029
// We have a packet to record. OpenDetached is the highest needed level here.
10251030
if (!NPF_StartUsingOpenInstance(Open, OpenDetached, AtDispatchLevel))
10261031
{
1027-
return;
1032+
return FALSE;
10281033
}
10291034

10301035
NT_ASSERT((Open->TimestampMode == TIMESTAMPMODE_SINGLE_SYNCHRONIZATION && pNBLCopy->PerfCount.QuadPart > 0)
@@ -1119,6 +1124,7 @@ NPF_TapExForEachOpen(
11191124
}
11201125
ExInterlockedInsertTailList(&Open->PacketQueue, &pCapData->PacketQueueEntry, &Open->PacketQueueLock);
11211126
// We successfully put this into the queue
1127+
bEnqueued = TRUE;
11221128
lCapSize = 0;
11231129
NpfInterlockedIncrement(&(LONG)Open->Accepted);
11241130

@@ -1129,7 +1135,7 @@ NPF_TapExForEachOpen(
11291135
}
11301136

11311137
} while (0);
1132-
if (lCapSize > 0)
1138+
if (!bEnqueued && lCapSize > 0)
11331139
{
11341140
// something went wrong and we didn't enqueue this, so reverse it.
11351141
NpfInterlockedExchangeAdd(&Open->Free, lCapSize);
@@ -1140,5 +1146,6 @@ NPF_TapExForEachOpen(
11401146

11411147

11421148
NPF_StopUsingOpenInstance(Open, OpenDetached, AtDispatchLevel);
1149+
return bEnqueued;
11431150
//TRACE_EXIT();
11441151
}

0 commit comments

Comments
 (0)