Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1808ec2

Browse files
author
Nikita Glukhov
committed
Fix memleaks in json encoding using temporary memory context
1 parent258209e commit1808ec2

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
@@ -1735,15 +1735,27 @@ convertToJsonb(const JsonbValue *val, JsonValueEncoder encoder)
17351735
{
17361736
StringInfoDatabuffer;
17371737
void*res;
1738+
MemoryContexttmpcxt,
1739+
oldcxt;
17381740

17391741
/* Allocate an output buffer. It will be enlarged as needed */
17401742
initStringInfo(&buffer);
17411743

17421744
/* Make room for the varlena header */
17431745
reserveFromBuffer(&buffer,VARHDRSZ);
17441746

1747+
tmpcxt=AllocSetContextCreate(CurrentMemoryContext,
1748+
"Json Encoding Context",
1749+
ALLOCSET_DEFAULT_MINSIZE,
1750+
ALLOCSET_DEFAULT_INITSIZE,
1751+
ALLOCSET_DEFAULT_MAXSIZE);
1752+
oldcxt=MemoryContextSwitchTo(tmpcxt);
1753+
17451754
(*encoder)(&buffer,val);
17461755

1756+
MemoryContextSwitchTo(oldcxt);
1757+
MemoryContextDelete(tmpcxt);
1758+
17471759
/*
17481760
* Note: the JEntry of the root is discarded. Therefore the root
17491761
* JsonbContainer struct must contain enough information to tell what kind

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp