Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Free pointer pAdapterInfo before the function nodeIdImpl returns #473

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mugitya03
Copy link

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
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.

2 participants