Content-Length: 288586 | pFad | http://github.com/postgrespro/postgres/commit/3204b877f34b59b83f2090c8ec887faa0a799e02

4B Fix memleaks in json encoding using temporary memory context · postgrespro/postgres@3204b87 · GitHub
Skip to content

Commit 3204b87

Browse files
author
Nikita Glukhov
committed
Fix memleaks in json encoding using temporary memory context
1 parent 321ddff commit 3204b87

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/backend/utils/adt/jsonb_util.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,15 +1672,27 @@ convertToJsonb(const JsonbValue *val, JsonValueEncoder encoder)
16721672
{
16731673
StringInfoData buffer;
16741674
void *res;
1675+
MemoryContext tmpcxt,
1676+
oldcxt;
16751677

16761678
/* Allocate an output buffer. It will be enlarged as needed */
16771679
initStringInfo(&buffer);
16781680

16791681
/* Make room for the varlena header */
16801682
reserveFromBuffer(&buffer, VARHDRSZ);
16811683

1684+
tmpcxt = AllocSetContextCreate(CurrentMemoryContext,
1685+
"Json Encoding Context",
1686+
ALLOCSET_DEFAULT_MINSIZE,
1687+
ALLOCSET_DEFAULT_INITSIZE,
1688+
ALLOCSET_DEFAULT_MAXSIZE);
1689+
oldcxt = MemoryContextSwitchTo(tmpcxt);
1690+
16821691
(*encoder)(&buffer, val);
16831692

1693+
MemoryContextSwitchTo(oldcxt);
1694+
MemoryContextDelete(tmpcxt);
1695+
16841696
/*
16851697
* Note: the JEntry of the root is discarded. Therefore the root
16861698
* JsonbContainer struct must contain enough information to tell what kind

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgrespro/postgres/commit/3204b877f34b59b83f2090c8ec887faa0a799e02

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy