Skip to content

Commit 4a1ca60

Browse files
committed
PGPRO-2160: to_files may be uninitialized if from_backup has BACKUP_STATUS_DELETING
1 parent cc6e2f8 commit 4a1ca60

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/merge.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
164164
control_file[MAXPGPATH];
165165
parray *files,
166166
*to_files;
167-
pthread_t *threads;
167+
pthread_t *threads = NULL;
168168
merge_files_arg *threads_args;
169169
int i;
170170
bool merge_isok = true;
@@ -193,19 +193,6 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
193193
if (from_backup->status == BACKUP_STATUS_CORRUPT)
194194
elog(ERROR, "Interrupt merging");
195195

196-
/*
197-
* Previous merging was interrupted during deleting source backup. It is
198-
* safe just to delete it again.
199-
*/
200-
if (from_backup->status == BACKUP_STATUS_DELETING)
201-
goto delete_source_backup;
202-
203-
to_backup->status = BACKUP_STATUS_MERGING;
204-
write_backup_status(to_backup);
205-
206-
from_backup->status = BACKUP_STATUS_MERGING;
207-
write_backup_status(from_backup);
208-
209196
/*
210197
* Make backup paths.
211198
*/
@@ -216,8 +203,6 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
216203
pgBackupGetPath(from_backup, from_database_path, lengthof(from_database_path),
217204
DATABASE_DIR);
218205

219-
create_data_directories(to_database_path, from_backup_path, false);
220-
221206
/*
222207
* Get list of files which will be modified or removed.
223208
*/
@@ -238,6 +223,21 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
238223
/* sort by size for load balancing */
239224
parray_qsort(files, pgFileCompareSize);
240225

226+
/*
227+
* Previous merging was interrupted during deleting source backup. It is
228+
* safe just to delete it again.
229+
*/
230+
if (from_backup->status == BACKUP_STATUS_DELETING)
231+
goto delete_source_backup;
232+
233+
to_backup->status = BACKUP_STATUS_MERGING;
234+
write_backup_status(to_backup);
235+
236+
from_backup->status = BACKUP_STATUS_MERGING;
237+
write_backup_status(from_backup);
238+
239+
create_data_directories(to_database_path, from_backup_path, false);
240+
241241
threads = (pthread_t *) palloc(sizeof(pthread_t) * num_threads);
242242
threads_args = (merge_files_arg *) palloc(sizeof(merge_files_arg) * num_threads);
243243

@@ -344,8 +344,11 @@ merge_backups(pgBackup *to_backup, pgBackup *from_backup)
344344
write_backup(to_backup);
345345

346346
/* Cleanup */
347-
pfree(threads_args);
348-
pfree(threads);
347+
if (threads)
348+
{
349+
pfree(threads_args);
350+
pfree(threads);
351+
}
349352

350353
parray_walk(to_files, pgFileFree);
351354
parray_free(to_files);

0 commit comments

Comments
 (0)