Fixed memory leak in ODBC::GetParametersFromArray#8
Merged
Conversation
Owner
|
Awesome find. Thank you for your work. Released v0.6.10 to npm. Cheers! |
clach04
pushed a commit
to clach04/node-odbc__DO_NOT_USE
that referenced
this pull request
Dec 17, 2020
Fixing both an SQL_FLOAT issue and boundRow garbage Data Fixes wankdanker#67 Fixes wankdanker#8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The bug occurs when a query is being executed with usage of parameters array where array is empty. Something along the lines of
In such cases,
ODBC::GetParametersFromArrayis being executed and sincevalues->Length()is equal to 0, the call tomalloceffectively becomesmalloc(0). Behavior of such call is not strictly defined. C99 standard states that either a null pointer should be returned or the call should behave as if the requested size was nonzero and a unique pointer is returned with the exception that the address should not be accessed (PDF Warning - ISO/IEC 9899:TC2, section 7.20.3, page 313).As it stands,
glibcdisplays the latter behavior, additionally defining a minimum allocated size.The actual cause of the leak is the fact that in all instances where the parameter array returned by
ODBC::GetParametersFromArrayis freed, it is only done under condition that there were more than 0 parameters in the query - example.Given enough time and enough queries, those several lost bytes did pile up.