mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-04 00:02:52 -05:00 
			
		
		
		
	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.
This commit is contained in:
		
							parent
							
								
									6f37c08057
								
							
						
					
					
						commit
						eb933162cd
					
				@ -376,13 +376,14 @@ readfile(const char *path)
 | 
				
			|||||||
void
 | 
					void
 | 
				
			||||||
free_readfile(char **optlines)
 | 
					free_readfile(char **optlines)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i = 0;
 | 
						char   *curr_line = NULL;
 | 
				
			||||||
 | 
						int		i = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!optlines)
 | 
						if (!optlines)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	while (optlines[i++])
 | 
						while ((curr_line = optlines[i++]))
 | 
				
			||||||
		free(optlines[i]);
 | 
							free(curr_line);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	free(optlines);
 | 
						free(optlines);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1224,6 +1225,7 @@ do_status(void)
 | 
				
			|||||||
			if (postmaster_is_alive((pid_t) pid))
 | 
								if (postmaster_is_alive((pid_t) pid))
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				char	  **optlines;
 | 
									char	  **optlines;
 | 
				
			||||||
 | 
									char	  **curr_line;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				printf(_("%s: server is running (PID: %ld)\n"),
 | 
									printf(_("%s: server is running (PID: %ld)\n"),
 | 
				
			||||||
					   progname, pid);
 | 
										   progname, pid);
 | 
				
			||||||
@ -1231,8 +1233,8 @@ do_status(void)
 | 
				
			|||||||
				optlines = readfile(postopts_file);
 | 
									optlines = readfile(postopts_file);
 | 
				
			||||||
				if (optlines != NULL)
 | 
									if (optlines != NULL)
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					for (; *optlines != NULL; optlines++)
 | 
										for (curr_line = optlines; *curr_line != NULL; curr_line++)
 | 
				
			||||||
						fputs(*optlines, stdout);
 | 
											fputs(*curr_line, stdout);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					/* Free the results of readfile */
 | 
										/* Free the results of readfile */
 | 
				
			||||||
					free_readfile(optlines);
 | 
										free_readfile(optlines);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user