Skip to content

Commit dc4da3d

Browse files
committed
Fix very minor memory leaks in psql's command.c.
\drds leaked its second pattern argument if any, and \connect leaked any empty-string or "-" arguments. These are old bugs, but it's hard to imagine any real use-case where the leaks could amount to anything meaningful, so not bothering with a back-patch. Daniel Gustafsson and Tom Lane Discussion: https://postgr.es/m/3641F19B-336A-431A-86CE-A80562505C5E@yesql.se
1 parent efd7f8e commit dc4da3d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/bin/psql/command.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,9 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd)
806806
pattern2 = psql_scan_slash_option(scan_state,
807807
OT_NORMAL, NULL, true);
808808
success = listDbRoleSettings(pattern, pattern2);
809+
810+
if (pattern2)
811+
free(pattern2);
809812
}
810813
else
811814
status = PSQL_CMD_UNKNOWN;
@@ -2725,6 +2728,8 @@ exec_command_slash_command_help(PsqlScanState scan_state, bool active_branch)
27252728

27262729
/*
27272730
* Read and interpret an argument to the \connect slash command.
2731+
*
2732+
* Returns a malloc'd string, or NULL if no/empty argument.
27282733
*/
27292734
static char *
27302735
read_connect_arg(PsqlScanState scan_state)
@@ -2750,7 +2755,10 @@ read_connect_arg(PsqlScanState scan_state)
27502755
return result;
27512756

27522757
if (*result == '\0' || strcmp(result, "-") == 0)
2758+
{
2759+
free(result);
27532760
return NULL;
2761+
}
27542762

27552763
return result;
27562764
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy