diff options
author | Stephen Frost <sfrost@snowman.net> | 2014-03-05 01:30:03 -0500 |
---|---|---|
committer | Stephen Frost <sfrost@snowman.net> | 2014-03-05 01:30:03 -0500 |
commit | eb933162cdcbcaa5c56c75eb21b9c055af9748a0 (patch) | |
tree | b1727d2f75327c5952f512d03d426e038aca52b9 | |
parent | 6f37c08057685ee3c6c63222dba0dac012760dde (diff) |
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.
-rw-r--r-- | src/bin/pg_ctl/pg_ctl.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index 5c79d101c98..ff84498a005 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -376,13 +376,14 @@ readfile(const char *path) void free_readfile(char **optlines) { - int i = 0; + char *curr_line = NULL; + int i = 0; if (!optlines) return; - while (optlines[i++]) - free(optlines[i]); + while ((curr_line = optlines[i++])) + free(curr_line); free(optlines); @@ -1224,6 +1225,7 @@ do_status(void) if (postmaster_is_alive((pid_t) pid)) { char **optlines; + char **curr_line; printf(_("%s: server is running (PID: %ld)\n"), progname, pid); @@ -1231,8 +1233,8 @@ do_status(void) optlines = readfile(postopts_file); if (optlines != NULL) { - for (; *optlines != NULL; optlines++) - fputs(*optlines, stdout); + for (curr_line = optlines; *curr_line != NULL; curr_line++) + fputs(*curr_line, stdout); /* Free the results of readfile */ free_readfile(optlines); |