Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit eb93316

Browse files
committed
Fix issues with pg_ctl
The new, small, free_readfile managed to have bug in it which could cause it to try and free something it shouldn't, and fix the case where it was being called with an invalid pointer leading to a segfault. Noted by Bruce, issues introduced and fixed by me.
1 parent 6f37c08 commit eb93316

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/bin/pg_ctl/pg_ctl.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,14 @@ readfile(const char *path)
376376
void
377377
free_readfile(char **optlines)
378378
{
379-
int i = 0;
379+
char *curr_line = NULL;
380+
int i = 0;
380381

381382
if (!optlines)
382383
return;
383384

384-
while (optlines[i++])
385-
free(optlines[i]);
385+
while ((curr_line = optlines[i++]))
386+
free(curr_line);
386387

387388
free(optlines);
388389

@@ -1224,15 +1225,16 @@ do_status(void)
12241225
if (postmaster_is_alive((pid_t) pid))
12251226
{
12261227
char **optlines;
1228+
char **curr_line;
12271229

12281230
printf(_("%s: server is running (PID: %ld)\n"),
12291231
progname, pid);
12301232

12311233
optlines = readfile(postopts_file);
12321234
if (optlines != NULL)
12331235
{
1234-
for (; *optlines != NULL; optlines++)
1235-
fputs(*optlines, stdout);
1236+
for (curr_line = optlines; *curr_line != NULL; curr_line++)
1237+
fputs(*curr_line, stdout);
12361238

12371239
/* Free the results of readfile */
12381240
free_readfile(optlines);

0 commit comments

Comments
 (0)