Skip to content

Commit

Permalink
Free buffer early when converting numeric
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Kasko <[email protected]>
  • Loading branch information
staticlibs committed Apr 1, 2024
1 parent 6606b11 commit 519742d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion contrib/babelfishpg_tds/src/backend/tds/tdstypeio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,8 @@ TdsTypeNumericToDatum(StringInfo buf, int scale)
Numeric res;
int len,
sign;
char *decString;
char *decString,
*decStringOrig;
int temp1,
temp2;
uint128 num = 0;
Expand All @@ -1131,6 +1132,7 @@ TdsTypeNumericToDatum(StringInfo buf, int scale)
}

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

if (num != 0)
Integer2String(num, decString);
Expand Down Expand Up @@ -1161,6 +1163,7 @@ 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);
}
Expand Down Expand Up @@ -1189,6 +1192,7 @@ TdsTypeNumericToDatum(StringInfo buf, int scale)
decString++;

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

Expand Down

0 comments on commit 519742d

Please sign in to comment.