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.
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);
if (postmaster_is_alive((pid_t) pid))
{
char **optlines;
+ char **curr_line;
printf(_("%s: server is running (PID: %ld)\n"),
progname, pid);
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);