Skip to content

Commit

Permalink
Free buffer early when converting numerics 2x (#2471)
Browse files Browse the repository at this point in the history
`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

#2455, BABEL-4882

Signed-off-by: Alex Kasko <alex@staticlibs.net>
  • Loading branch information
staticlibs committed Apr 8, 2024
1 parent 36fd92e commit fe50406
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion contrib/babelfishpg_tds/src/backend/tds/tdstypeio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,8 @@ TdsTypeNumericToDatum(StringInfo buf, int scale)
Numeric res;
int len,
sign;
char *decString;
char *decString,
*decStringOrig;
int temp1,
temp2;
uint128 num = 0;
Expand All @@ -1088,6 +1089,7 @@ TdsTypeNumericToDatum(StringInfo buf, int scale)
}

decString = (char *) palloc0(sizeof(char) * 40);
decStringOrig = decString;

if (num != 0)
Integer2String(num, decString);
Expand Down Expand Up @@ -1118,8 +1120,10 @@ TdsTypeNumericToDatum(StringInfo buf, int scale)
* index during shifting the scale part of the string.
*/
decString = psprintf("-%s%s.", zeros, tempString + 1);
decStringOrig = decString;
len = strlen(decString) - 1;
pfree(tempString);
pfree(zeros);
}
if (num != 0)
{
Expand All @@ -1146,6 +1150,7 @@ TdsTypeNumericToDatum(StringInfo buf, int scale)
decString++;

res = TdsSetVarFromStrWrapper(decString);
pfree(decStringOrig);
PG_RETURN_NUMERIC(res);
}

Expand Down

0 comments on commit fe50406

Please sign in to comment.