Skip to content

Commit 7f58900

Browse files
authored
Improve allocation of buffer when obtaining TCP/UDP connection/listeners (#128551)
PR Improves how is buffer size computed when allocating buffer passed to sysctl calls.
1 parent 49bb6a0 commit 7f58900

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/native/libs/System.Native/pal_networkstatistics.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ int32_t SystemNative_GetActiveTcpConnectionInfos(NativeTcpConnectionInformation*
379379
free(buffer);
380380
size_t tmpEstimatedSize;
381381
if (!multiply_s(estimatedSize, (size_t)2, &tmpEstimatedSize) ||
382-
(buffer = (uint8_t*)malloc(estimatedSize * sizeof(uint8_t))) == NULL)
382+
(buffer = (uint8_t*)malloc(tmpEstimatedSize * sizeof(uint8_t))) == NULL)
383383
{
384384
errno = ENOMEM;
385385
return -1;
@@ -493,7 +493,7 @@ int32_t SystemNative_GetActiveUdpListeners(IPEndPointInfo* infos, int32_t* infoC
493493
free(buffer);
494494
size_t tmpEstimatedSize;
495495
if (!multiply_s(estimatedSize, (size_t)2, &tmpEstimatedSize) ||
496-
(buffer = (uint8_t*)malloc(estimatedSize * sizeof(uint8_t))) == NULL)
496+
(buffer = (uint8_t*)malloc(tmpEstimatedSize * sizeof(uint8_t))) == NULL)
497497
{
498498
errno = ENOMEM;
499499
return -1;

0 commit comments

Comments
 (0)