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

Commitc2fb2f9

Browse files
committed
psql: Fix memory leak with repeated calls of \bind
Calling \bind repeatedly would cause the memory allocated for the listof bind parameters to be leaked after each call, as the list is resetwhen beginning a single call.This issue is fixed by making the cleanup of the bind parameter listmore aggressive, refactoring it into a single routine called afterprocessing a query and before running an individual \bind.HEAD required more surgery and has been fixed by87eeada. Issueintroduced by5b66de3.Reported-by: Anthonin BonnefoyDiscussion:https://postgr.es/m/2e5b89af-a351-ff0a-000c-037ac28314ab@gmail.comBackpatch-through: 16
1 parent00c8c41 commitc2fb2f9

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

‎src/bin/psql/command.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ exec_command_bind(PsqlScanState scan_state, bool active_branch)
470470
intnparams=0;
471471
intnalloc=0;
472472

473-
pset.bind_params=NULL;
473+
clean_bind_state();
474474

475475
while ((opt=psql_scan_slash_option(scan_state,OT_NORMAL,NULL, false)))
476476
{

‎src/bin/psql/common.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,14 +1241,7 @@ SendQuery(const char *query)
12411241
}
12421242

12431243
/* clean up after \bind */
1244-
if (pset.bind_flag)
1245-
{
1246-
for (i=0;i<pset.bind_nparams;i++)
1247-
free(pset.bind_params[i]);
1248-
free(pset.bind_params);
1249-
pset.bind_params=NULL;
1250-
pset.bind_flag= false;
1251-
}
1244+
clean_bind_state();
12521245

12531246
/* reset \gset trigger */
12541247
if (pset.gset_prefix)
@@ -2413,6 +2406,26 @@ uri_prefix_length(const char *connstr)
24132406
return0;
24142407
}
24152408

2409+
/*
2410+
* Reset state related to \bind
2411+
*
2412+
* Clean up any state related to bind parameters and bind_flag. This needs
2413+
* to be called after processing a query or when running \bind.
2414+
*/
2415+
void
2416+
clean_bind_state(void)
2417+
{
2418+
if (pset.bind_flag)
2419+
{
2420+
for (inti=0;i<pset.bind_nparams;i++)
2421+
free(pset.bind_params[i]);
2422+
free(pset.bind_params);
2423+
}
2424+
2425+
pset.bind_params=NULL;
2426+
pset.bind_flag= false;
2427+
}
2428+
24162429
/*
24172430
* Recognized connection string either starts with a valid URI prefix or
24182431
* contains a "=" in it.

‎src/bin/psql/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extern bool standard_strings(void);
4141
externconstchar*session_username(void);
4242

4343
externvoidexpand_tilde(char**filename);
44+
externvoidclean_bind_state(void);
4445

4546
externboolrecognized_connection_string(constchar*connstr);
4647

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp