Skip to content

Commit a9d58bf

Browse files
committed
Fix tiny memory leaks
Both check_application_name() and check_cluster_name() use pg_clean_ascii() but didn't release the memory. Depending on when the GUC is set, this might be cleaned up at some later time or it would leak postmaster memory once. In any case, it seems better not to have to rely on such analysis and make the code locally robust. Also, this makes Valgrind happier. Author: Masahiko Sawada <[email protected]> Reviewed-by: Jacob Champion <[email protected]> Discussion: https://www.postgresql.org/message-id/CAD21AoBmFNy9MPfA0UUbMubQqH3AaK5U3mrv6pSeWrwCk3LJ8g@mail.gmail.com
1 parent 83e42a0 commit a9d58bf

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/backend/commands/variable.c

+16-6
Original file line numberDiff line numberDiff line change
@@ -1025,17 +1025,22 @@ bool
10251025
check_application_name(char **newval, void **extra, GucSource source)
10261026
{
10271027
char *clean;
1028+
char *ret;
10281029

10291030
/* Only allow clean ASCII chars in the application name */
10301031
clean = pg_clean_ascii(*newval, MCXT_ALLOC_NO_OOM);
10311032
if (!clean)
10321033
return false;
10331034

1034-
clean = guc_strdup(WARNING, clean);
1035-
if (!clean)
1035+
ret = guc_strdup(WARNING, clean);
1036+
if (!ret)
1037+
{
1038+
pfree(clean);
10361039
return false;
1040+
}
10371041

1038-
*newval = clean;
1042+
pfree(clean);
1043+
*newval = ret;
10391044
return true;
10401045
}
10411046

@@ -1056,17 +1061,22 @@ bool
10561061
check_cluster_name(char **newval, void **extra, GucSource source)
10571062
{
10581063
char *clean;
1064+
char *ret;
10591065

10601066
/* Only allow clean ASCII chars in the cluster name */
10611067
clean = pg_clean_ascii(*newval, MCXT_ALLOC_NO_OOM);
10621068
if (!clean)
10631069
return false;
10641070

1065-
clean = guc_strdup(WARNING, clean);
1066-
if (!clean)
1071+
ret = guc_strdup(WARNING, clean);
1072+
if (!ret)
1073+
{
1074+
pfree(clean);
10671075
return false;
1076+
}
10681077

1069-
*newval = clean;
1078+
pfree(clean);
1079+
*newval = ret;
10701080
return true;
10711081
}
10721082

0 commit comments

Comments
 (0)