Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

Memory leak with CSList::ThrowAll() in NTFS_Common.h #268

Open
EyeOfRa opened this issue Oct 26, 2017 · 0 comments
Open

Memory leak with CSList::ThrowAll() in NTFS_Common.h #268

EyeOfRa opened this issue Oct 26, 2017 · 0 comments

Comments

@EyeOfRa
Copy link

EyeOfRa commented Oct 26, 2017

I found a mistake of using (or implement) with CSList::ThrowAll(). With ThrowAll() you want to give the responsibility of memory freeing to the object that the list assigned for. But in your InsertEntry() function, it just assigns only the pointer of ENTRY_TYPE not the pointer of NTSLIST_ENTRY and those pointers will never be freed.

BOOL InsertEntry(ENTRY_TYPE *entry)
{
NTSLIST_ENTRY<ENTRY_TYPE> *le = new NTSLIST_ENTRY<ENTRY_TYPE>;
if (!le)
return FALSE;
le->Entry = entry;
le->Next = NULL;
if (ListTail == NULL)
ListHead = le; // Empty list
else
ListTail->Next = le;
ListTail = le;
EntryCount++;
return TRUE;
}

So in the ThrowAll(), you must free the NTSLIST_ENTRY before throwing all to NULL.

__inline void ThrowAll()
{
	// My fix
	while (ListHead)
	{
		ListCurrent = ListHead->Next;
		ListHead->Entry = NULL;
		delete ListHead;

		ListHead = ListCurrent;
	}
	// End my fix
	ListHead = ListTail = NULL;
	ListCurrent = NULL;
	EntryCount = 0;
}
@EyeOfRa EyeOfRa changed the title Memory leak with CSList::ThrowAll() Memory leak with CSList::ThrowAll() in NTFS_Common.h Oct 26, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant