Not sure why the format is messed up! Sorry, it wasn't like this when I clicked submit.
Potential bug causing GetPerTcpConnectionEStats to free user allocated buffer when called?

I just registered here to ask/report this. This is my code:
for (DWORD i = 0; i < ptTable->dwNumEntries; i++)
{ MIB_TCPROW row;
row.dwLocalAddr = ptTable->table[i].dwLocalAddr;
row.dwLocalPort = ptTable->table[i].dwLocalPort;
row.dwRemoteAddr = ptTable->table[i].dwRemoteAddr;
row.dwRemotePort = ptTable->table[i].dwRemotePort;
row.dwState = ptTable->table[i].dwState;
if (row.dwRemoteAddr)
{
std::unique_ptr<UCHAR> rod = std::unique_ptr<UCHAR>(new UCHAR[rodSize]());
ret = GetPerTcpConnectionEStats
} ((PMIB_TCPROW)&row, TcpConnectionEstatsData, NULL, 0, 0, 0, 0, 0, (PUCHAR)rod.get(), 0, rodSize);
}
Whenever GetPerTcpConnectionEStats is called, the buffer gets freed (the bytes turn into 0xdd 0xdd...).
Note: The problem does not always occur. Within the same debuging session, it happens about 20 times out 100 "for loop" iterations given that every iteration calls GetPerTcpConnectionEStats twice, and only the first call (the one above) causes it.
Also the return from GetPerTcpConnectionEStats is NO_ERROR in all cases. Is it my code that's causing the problem or GetPerTcpConnectionEStats itself is broken?
Cheers
2 answers
Sort by: Most helpful
-
-
Freedom Sy 26 Reputation points
2021-02-22T13:19:34.047+00:00 This post is now more like a report, because it seems to work just fine if you don't heap allocate at all. The following code works for me, might not work for everyone though:
TCP_ESTATS_DATA_ROD_v0 rod = { 0 }; ret= GetPerTcpConnectionEStats((PMIB_TCPROW)&row, TcpConnectionEstatsData, NULL, 0, 0, 0, 0, 0, (PUCHAR)&rod, 0, sizeof(TCP_ESTATS_DATA_ROD_v0));