Skip to content

Commit 9ee0a7d

Browse files
committed
Fix some allocation size calculation errors that would cause pgbench
to fail with large test scripts.
1 parent 4a57a45 commit 9ee0a7d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

contrib/pgbench/pgbench.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.44 2005/10/15 20:24:00 tgl Exp $
2+
* $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.45 2005/10/29 19:38:07 tgl Exp $
33
*
44
* pgbench: a simple benchmark program for PostgreSQL
55
* written by Tatsuo Ishii
@@ -868,15 +868,15 @@ process_file(char *filename)
868868
}
869869

870870
alloc_num = COMMANDS_ALLOC_NUM;
871-
my_commands = (Command **) malloc(sizeof(Command **) * alloc_num);
871+
my_commands = (Command **) malloc(sizeof(Command *) * alloc_num);
872872
if (my_commands == NULL)
873873
return false;
874874

875875
if (strcmp(filename, "-") == 0)
876876
fd = stdin;
877877
else if ((fd = fopen(filename, "r")) == NULL)
878878
{
879-
fprintf(stderr, "%s: %s\n", strerror(errno), filename);
879+
fprintf(stderr, "%s: %s\n", filename, strerror(errno));
880880
return false;
881881
}
882882

@@ -899,7 +899,7 @@ process_file(char *filename)
899899
if (lineno >= alloc_num)
900900
{
901901
alloc_num += COMMANDS_ALLOC_NUM;
902-
my_commands = realloc(my_commands, alloc_num);
902+
my_commands = realloc(my_commands, sizeof(Command *) * alloc_num);
903903
if (my_commands == NULL)
904904
{
905905
fclose(fd);
@@ -930,7 +930,7 @@ process_builtin(char *tb)
930930
return NULL;
931931

932932
alloc_num = COMMANDS_ALLOC_NUM;
933-
my_commands = malloc(sizeof(Command **) * alloc_num);
933+
my_commands = (Command **) malloc(sizeof(Command *) * alloc_num);
934934
if (my_commands == NULL)
935935
return NULL;
936936

@@ -965,7 +965,7 @@ process_builtin(char *tb)
965965
if (lineno >= alloc_num)
966966
{
967967
alloc_num += COMMANDS_ALLOC_NUM;
968-
my_commands = realloc(my_commands, alloc_num);
968+
my_commands = realloc(my_commands, sizeof(Command *) * alloc_num);
969969
if (my_commands == NULL)
970970
{
971971
return NULL;
@@ -1031,7 +1031,7 @@ main(int argc, char **argv)
10311031
* 2: skip update of branches and tellers */
10321032
char *filename = NULL;
10331033

1034-
static CState *state; /* status of clients */
1034+
CState *state; /* status of clients */
10351035

10361036
struct timeval tv1; /* start up time */
10371037
struct timeval tv2; /* after establishing all connections to the
@@ -1101,7 +1101,7 @@ main(int argc, char **argv)
11011101
if (getrlimit(RLIMIT_OFILE, &rlim) == -1)
11021102
#endif /* RLIMIT_NOFILE */
11031103
{
1104-
fprintf(stderr, "getrlimit failed. reason: %s\n", strerror(errno));
1104+
fprintf(stderr, "getrlimit failed: %s\n", strerror(errno));
11051105
exit(1);
11061106
}
11071107
if (rlim.rlim_cur <= (nclients + 2))
@@ -1173,7 +1173,7 @@ main(int argc, char **argv)
11731173

11741174
remains = nclients;
11751175

1176-
state = (CState *) malloc(sizeof(*state) * nclients);
1176+
state = (CState *) malloc(sizeof(CState) * nclients);
11771177
if (state == NULL)
11781178
{
11791179
fprintf(stderr, "Couldn't allocate memory for state\n");

0 commit comments

Comments
 (0)