Skip to content

Free pointer pAdapterInfo before the function nodeIdImpl returns#473

Merged
slabko merged 1 commit intoClickHouse:masterfrom
mugitya03:master
Mar 3, 2025
Merged

Free pointer pAdapterInfo before the function nodeIdImpl returns#473
slabko merged 1 commit intoClickHouse:masterfrom
mugitya03:master

Conversation

@mugitya03
Copy link
Contributor

In function nodeIdImpl, the pointer pAdapterInfo at line 8 cannot reach any free site before the function returns at line 19. Thus there is a memory leak bug. Here is the original code:

	pAdapterInfo = reinterpret_cast<IP_ADAPTER_INFO*>(new char[len]);         // memory allocated here
	// Make an initial call to GetAdaptersInfo to get
	// the necessary size into len
	DWORD rc = GetAdaptersInfo(pAdapterInfo, &len);
	if (rc == ERROR_BUFFER_OVERFLOW) 
	{
		delete [] reinterpret_cast<char*>(pAdapterInfo);
		pAdapterInfo = reinterpret_cast<IP_ADAPTER_INFO*>(new char[len]);
	}
	else if (rc != ERROR_SUCCESS)
	{
		return;          // memory leak here
	}

We add a free operation before the return statement.

In function `nodeIdImpl`, the pointer `pAdapterInfo` at line 8 cannot reach any free site before the function returns at line 19. Thus there is a memory leak bug.

We add a free operation before the return statement.
@CLAassistant
Copy link

CLAassistant commented Feb 26, 2025

CLA assistant check
All committers have signed the CLA.

@mshustov mshustov requested a review from slabko February 27, 2025 12:37
@slabko
Copy link
Contributor

slabko commented Mar 3, 2025

@mugitya03 thank you very much for your contribution.
This is indeed a memory leak in poco. I can even see that it was been fixed in pocoproject/poco@d11e48f

@slabko slabko merged commit eef3f28 into ClickHouse:master Mar 3, 2025
7 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants