-
Notifications
You must be signed in to change notification settings - Fork 88
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 buffer early when converting numerics #2456
Free buffer early when converting numerics #2456
Conversation
Signed-off-by: Alex Kasko <alex@staticlibs.net>
Pull Request Test Coverage Report for Build 8554170845Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
@@ -1189,6 +1192,7 @@ TdsTypeNumericToDatum(StringInfo buf, int scale) | |||
decString++; | |||
|
|||
res = TdsSetVarFromStrWrapper(decString); | |||
pfree(decStringOrig); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I couldn't add comment above, but we should free memory allocated to zeros on line no. 1153
- Just to safer side and to avoid double free, use if (decStringOrig) then free
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is no chance that decStringOrig is going to be NULL here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added memory free call to zeros buffer. Agree about the NULL checks before calling pfree, just in this case decStringOrig should not be NULL on any code path.
Signed-off-by: Alex Kasko <alex@staticlibs.net>
We should fix this in other dev branches also, BABEL_2_X_DEV and BABEL_3_X_DEV |
Thanks for the review! I've filed PRs for 3x and 2x. |
Related Jira: BABEL-4882 |
3d2354e
into
babelfish-for-postgresql:BABEL_4_X_DEV
…2456) `TdsTypeNumericToDatum` [allocates a buffer](https://github.com/babelfish-for postgresql/babelfish_extensions/blob/6606b1118978477186869c3dddd2c6d85fcc6387/contrib/babelfishpg_tds/src/backend/tds/tdstypeio.c#L1133) for parsing incoming numeric data, but does not release this buffer. So it remains in `MessageContext` until the end of BCP import call. Proposed patch frees this buffer before exiting `TdsTypeNumericToDatum`. ### Issues Resolved babelfish-for-postgresql#2455, BABEL-4882 Signed-off-by: Alex Kasko <alex@staticlibs.net>
Description
TdsTypeNumericToDatum
allocates a buffer for parsing incoming numeric data, but does not release this buffer. So it remains inMessageContext
until the end of BCP import call.Proposed patch frees this buffer before exiting
TdsTypeNumericToDatum
.Backend memory usage when importing 1 million decimals (see details in linked issue) without the patch:
With patch applied:
Issues Resolved
#2455
Test Scenarios Covered
There are no functional changes, so no new tests.
Check List
By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.
Signed-off-by: Alex Kasko alex@staticlibs.net