mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
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:
@ -1025,17 +1025,22 @@ bool
|
|||||||
check_application_name(char **newval, void **extra, GucSource source)
|
check_application_name(char **newval, void **extra, GucSource source)
|
||||||
{
|
{
|
||||||
char *clean;
|
char *clean;
|
||||||
|
char *ret;
|
||||||
|
|
||||||
/* Only allow clean ASCII chars in the application name */
|
/* Only allow clean ASCII chars in the application name */
|
||||||
clean = pg_clean_ascii(*newval, MCXT_ALLOC_NO_OOM);
|
clean = pg_clean_ascii(*newval, MCXT_ALLOC_NO_OOM);
|
||||||
if (!clean)
|
if (!clean)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
clean = guc_strdup(WARNING, clean);
|
ret = guc_strdup(WARNING, clean);
|
||||||
if (!clean)
|
if (!ret)
|
||||||
|
{
|
||||||
|
pfree(clean);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
*newval = clean;
|
pfree(clean);
|
||||||
|
*newval = ret;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1056,17 +1061,22 @@ bool
|
|||||||
check_cluster_name(char **newval, void **extra, GucSource source)
|
check_cluster_name(char **newval, void **extra, GucSource source)
|
||||||
{
|
{
|
||||||
char *clean;
|
char *clean;
|
||||||
|
char *ret;
|
||||||
|
|
||||||
/* Only allow clean ASCII chars in the cluster name */
|
/* Only allow clean ASCII chars in the cluster name */
|
||||||
clean = pg_clean_ascii(*newval, MCXT_ALLOC_NO_OOM);
|
clean = pg_clean_ascii(*newval, MCXT_ALLOC_NO_OOM);
|
||||||
if (!clean)
|
if (!clean)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
clean = guc_strdup(WARNING, clean);
|
ret = guc_strdup(WARNING, clean);
|
||||||
if (!clean)
|
if (!ret)
|
||||||
|
{
|
||||||
|
pfree(clean);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
*newval = clean;
|
pfree(clean);
|
||||||
|
*newval = ret;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user