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 <sawada.mshk@gmail.com>
Reviewed-by: Jacob Champion <jchampion@timescale.com>
Discussion: https://www.postgresql.org/message-id/CAD21AoBmFNy9MPfA0UUbMubQqH3AaK5U3mrv6pSeWrwCk3LJ8g@mail.gmail.com
This commit is contained in:
Peter Eisentraut 2022-10-01 12:48:24 +02:00
parent 83e42a0035
commit a9d58bfe8a
1 changed files with 16 additions and 6 deletions

View File

@ -1025,17 +1025,22 @@ bool
check_application_name(char **newval, void **extra, GucSource source)
{
char *clean;
char *ret;
/* Only allow clean ASCII chars in the application name */
clean = pg_clean_ascii(*newval, MCXT_ALLOC_NO_OOM);
if (!clean)
return false;
clean = guc_strdup(WARNING, clean);
if (!clean)
ret = guc_strdup(WARNING, clean);
if (!ret)
{
pfree(clean);
return false;
}
*newval = clean;
pfree(clean);
*newval = ret;
return true;
}
@ -1056,17 +1061,22 @@ bool
check_cluster_name(char **newval, void **extra, GucSource source)
{
char *clean;
char *ret;
/* Only allow clean ASCII chars in the cluster name */
clean = pg_clean_ascii(*newval, MCXT_ALLOC_NO_OOM);
if (!clean)
return false;
clean = guc_strdup(WARNING, clean);
if (!clean)
ret = guc_strdup(WARNING, clean);
if (!ret)
{
pfree(clean);
return false;
}
*newval = clean;
pfree(clean);
*newval = ret;
return true;
}