Skip to content

Commit c958d6a

Browse files
author
Nikita Glukhov
committed
Fix memleaks in json encoding using temporary memory context
1 parent 9429f3f commit c958d6a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/backend/utils/adt/jsonb_util.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,12 +1742,29 @@ void *
17421742
JsonEncode(const JsonbValue *val, JsonValueEncoder encoder, void *cxt)
17431743
{
17441744
StringInfoData buffer;
1745+
#if 0
1746+
MemoryContext tmpcxt,
1747+
oldcxt;
1748+
#endif
17451749

17461750
/* Allocate an output buffer. It will be enlarged as needed */
17471751
initStringInfo(&buffer);
17481752

1753+
#if 0
1754+
tmpcxt = AllocSetContextCreate(CurrentMemoryContext,
1755+
"Json Encoding Context",
1756+
ALLOCSET_DEFAULT_MINSIZE,
1757+
ALLOCSET_DEFAULT_INITSIZE,
1758+
ALLOCSET_DEFAULT_MAXSIZE);
1759+
oldcxt = MemoryContextSwitchTo(tmpcxt);
1760+
#endif
1761+
17491762
(*encoder)(&buffer, val, cxt);
17501763

1764+
#if 0
1765+
MemoryContextSwitchTo(oldcxt);
1766+
MemoryContextDelete(tmpcxt);
1767+
#endif
17511768
/*
17521769
* Note: the JEntry of the root is discarded. Therefore the root
17531770
* JsonbContainer struct must contain enough information to tell what kind

0 commit comments

Comments
 (0)