Skip to content

Fixed memory leak in ODBC::GetParametersFromArray#8

Merged
wankdanker merged 1 commit into
wankdanker:masterfrom
Xylem:master
Jun 17, 2014
Merged

Fixed memory leak in ODBC::GetParametersFromArray#8
wankdanker merged 1 commit into
wankdanker:masterfrom
Xylem:master

Conversation

@Xylem
Copy link
Copy Markdown

@Xylem Xylem commented Jun 17, 2014

The bug occurs when a query is being executed with usage of parameters array where array is empty. Something along the lines of

connection.query('SELECT 1;', [], function (err, result) { ... });

In such cases, ODBC::GetParametersFromArray is being executed and since values->Length() is equal to 0, the call to malloc effectively becomes malloc(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, glibc displays 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::GetParametersFromArray is 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.

@wankdanker wankdanker merged commit 0c4bb92 into wankdanker:master Jun 17, 2014
@wankdanker
Copy link
Copy Markdown
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
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