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

Commit34f5119

Browse files
committed
Fix pgbench in prepared mode with an empty pipeline
It crashes because it references memory that's not allocated in thatparticular case. Fix by allocating it.Reported-by: Alexander Lakhin <exclusion@gmail.com>Discussion:https://postgr.es/m/bcf802a6-afc1-95b9-7bf4-c5dd868ec144@gmail.com
1 parent4729d1e commit34f5119

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

‎src/bin/pgbench/pgbench.c

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3070,6 +3070,27 @@ chooseScript(TState *thread)
30703070
returni-1;
30713071
}
30723072

3073+
/*
3074+
* Allocate space for CState->prepared: we need one boolean for each command
3075+
* of each script.
3076+
*/
3077+
staticvoid
3078+
allocCStatePrepared(CState*st)
3079+
{
3080+
Assert(st->prepared==NULL);
3081+
3082+
st->prepared=pg_malloc(sizeof(bool*)*num_scripts);
3083+
for (inti=0;i<num_scripts;i++)
3084+
{
3085+
ParsedScript*script=&sql_script[i];
3086+
intnumcmds;
3087+
3088+
for (numcmds=0;script->commands[numcmds]!=NULL;numcmds++)
3089+
;
3090+
st->prepared[i]=pg_malloc0(sizeof(bool)*numcmds);
3091+
}
3092+
}
3093+
30733094
/*
30743095
* Prepare the SQL command from st->use_file at command_num.
30753096
*/
@@ -3082,23 +3103,8 @@ prepareCommand(CState *st, int command_num)
30823103
if (command->type!=SQL_COMMAND)
30833104
return;
30843105

3085-
/*
3086-
* If not already done, allocate space for 'prepared' flags: one boolean
3087-
* for each command of each script.
3088-
*/
30893106
if (!st->prepared)
3090-
{
3091-
st->prepared=pg_malloc(sizeof(bool*)*num_scripts);
3092-
for (inti=0;i<num_scripts;i++)
3093-
{
3094-
ParsedScript*script=&sql_script[i];
3095-
intnumcmds;
3096-
3097-
for (numcmds=0;script->commands[numcmds]!=NULL;numcmds++)
3098-
;
3099-
st->prepared[i]=pg_malloc0(sizeof(bool)*numcmds);
3100-
}
3101-
}
3107+
allocCStatePrepared(st);
31023108

31033109
if (!st->prepared[st->use_file][command_num])
31043110
{
@@ -3130,13 +3136,15 @@ prepareCommandsInPipeline(CState *st)
31303136
Assert(commands[st->command]->type==META_COMMAND&&
31313137
commands[st->command]->meta==META_STARTPIPELINE);
31323138

3139+
if (!st->prepared)
3140+
allocCStatePrepared(st);
3141+
31333142
/*
31343143
* We set the 'prepared' flag on the \startpipeline itself to flag that we
31353144
* don't need to do this next time without calling prepareCommand(), even
31363145
* though we don't actually prepare this command.
31373146
*/
3138-
if (st->prepared&&
3139-
st->prepared[st->use_file][st->command])
3147+
if (st->prepared[st->use_file][st->command])
31403148
return;
31413149

31423150
for (j=st->command+1;commands[j]!=NULL;j++)

‎src/bin/pgbench/t/001_pgbench_with_server.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,8 @@
790790
'001_pgbench_pipeline_prep'=>q{
791791
-- test startpipeline
792792
\startpipeline
793+
\endpipeline
794+
\startpipeline
793795
} ."select 1;\n"x10 .q{
794796
\endpipeline
795797
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp