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

Commitbd489c6

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

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
@@ -1599,15 +1599,27 @@ convertToJsonb(const JsonbValue *val, JsonValueEncoder encoder,
15991599
{
16001600
StringInfoDatabuffer;
16011601
void*res;
1602+
MemoryContexttmpcxt,
1603+
oldcxt;
16021604

16031605
/* Allocate an output buffer. It will be enlarged as needed */
16041606
initStringInfo(&buffer);
16051607

16061608
/* Make room for the varlena header */
16071609
reserveFromBuffer(&buffer,VARHDRSZ);
16081610

1611+
tmpcxt=AllocSetContextCreate(CurrentMemoryContext,
1612+
"Json Encoding Context",
1613+
ALLOCSET_DEFAULT_MINSIZE,
1614+
ALLOCSET_DEFAULT_INITSIZE,
1615+
ALLOCSET_DEFAULT_MAXSIZE);
1616+
oldcxt=MemoryContextSwitchTo(tmpcxt);
1617+
16091618
(*encoder)(&buffer,val,options);
16101619

1620+
MemoryContextSwitchTo(oldcxt);
1621+
MemoryContextDelete(tmpcxt);
1622+
16111623
/*
16121624
* Note: the JEntry of the root is discarded. Therefore the root
16131625
* JsonbContainer struct must contain enough information to tell what kind

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp