Fix Memory Leak in System.DirectoryServices.Protocols caused by not freeing native memory #41053
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #40946
Fixes #39009
During the refactoring of S.DS.P, we changed some code that would get the search results back from an LDAP server and accidentally started calling the wrong native call to free the memory coming back from that result, causing it to a) have a big memory leak especially when we were getting a lot of results back and also b) we were sometimes causing a SegFault abort when we would sometimes free memory we didn't own. This PR will call ldap_msgfree instead of ldap_memfree to fix that issue and I have validated that the memory leak is fixed after this, and we don't have consistent repro for the memory corruption issue but will be most likely fixed by this as well.
cc: @tarekgh @danmosemsft @jkotas