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

Commit59ea9ef

Browse files
committed
Use palloc in TopMemoryContext instead of malloc
As discussed, even if the PL needs a permanent memory location, itshould use palloc, not malloc. It also makes error handling easier.Jan Urbański
1 parent88047e5 commit59ea9ef

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

‎src/pl/plpython/plpython.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ PLy_procedure_compile(PLyProcedure *proc, const char *src)
16051605
*/
16061606
msrc=PLy_procedure_munge_source(proc->pyname,src);
16071607
crv=PyRun_String(msrc,Py_file_input,proc->globals,NULL);
1608-
free(msrc);
1608+
pfree(msrc);
16091609

16101610
if (crv!=NULL)
16111611
{
@@ -1642,7 +1642,7 @@ PLy_procedure_munge_source(const char *name, const char *src)
16421642
*/
16431643
mlen= (strlen(src)*2)+strlen(name)+16;
16441644

1645-
mrc=PLy_malloc(mlen);
1645+
mrc=palloc(mlen);
16461646
plen=snprintf(mrc,mlen,"def %s():\n\t",name);
16471647
Assert(plen >=0&&plen<mlen);
16481648

@@ -3664,13 +3664,8 @@ PLy_traceback(int *xlevel)
36643664
staticvoid*
36653665
PLy_malloc(size_tbytes)
36663666
{
3667-
void*ptr=malloc(bytes);
3668-
3669-
if (ptr==NULL)
3670-
ereport(FATAL,
3671-
(errcode(ERRCODE_OUT_OF_MEMORY),
3672-
errmsg("out of memory")));
3673-
returnptr;
3667+
/* We need our allocations to be long-lived, so use TopMemoryContext */
3668+
returnMemoryContextAlloc(TopMemoryContext,bytes);
36743669
}
36753670

36763671
staticvoid*
@@ -3699,7 +3694,7 @@ PLy_strdup(const char *str)
36993694
staticvoid
37003695
PLy_free(void*ptr)
37013696
{
3702-
free(ptr);
3697+
pfree(ptr);
37033698
}
37043699

37053700
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp