xz: Use "goto" for error handling in io_open_dest_real()

This commit is contained in:
Lasse Collin 2024-12-27 09:15:50 +02:00
parent 7510721767
commit 2e28c71457
No known key found for this signature in database
GPG Key ID: 38EE757D69184620
1 changed files with 9 additions and 11 deletions

View File

@ -828,8 +828,7 @@ io_open_dest_real(file_pair *pair)
"a DOS special file", "a DOS special file",
tuklib_mask_nonprint( tuklib_mask_nonprint(
pair->dest_name)); pair->dest_name));
free(pair->dest_name); goto error;
return true;
} }
// Check that we aren't overwriting the source file. // Check that we aren't overwriting the source file.
@ -839,8 +838,7 @@ io_open_dest_real(file_pair *pair)
"as the input file", "as the input file",
tuklib_mask_nonprint( tuklib_mask_nonprint(
pair->dest_name)); pair->dest_name));
free(pair->dest_name); goto error;
return true;
} }
} }
#endif #endif
@ -850,8 +848,7 @@ io_open_dest_real(file_pair *pair)
message_error(_("%s: Cannot remove: %s"), message_error(_("%s: Cannot remove: %s"),
tuklib_mask_nonprint(pair->dest_name), tuklib_mask_nonprint(pair->dest_name),
strerror(errno)); strerror(errno));
free(pair->dest_name); goto error;
return true;
} }
// Open the file. // Open the file.
@ -867,8 +864,7 @@ io_open_dest_real(file_pair *pair)
message_error(_("%s: %s"), message_error(_("%s: %s"),
tuklib_mask_nonprint(pair->dest_name), tuklib_mask_nonprint(pair->dest_name),
strerror(errno)); strerror(errno));
free(pair->dest_name); goto error;
return true;
} }
} }
@ -901,9 +897,7 @@ io_open_dest_real(file_pair *pair)
// dest_fd needs to be reset to -1 to keep io_close() working. // dest_fd needs to be reset to -1 to keep io_close() working.
(void)close(pair->dest_fd); (void)close(pair->dest_fd);
pair->dest_fd = -1; pair->dest_fd = -1;
goto error;
free(pair->dest_name);
return true;
} }
#elif !defined(TUKLIB_DOSLIKE) #elif !defined(TUKLIB_DOSLIKE)
else if (try_sparse && opt_mode == MODE_DECOMPRESS) { else if (try_sparse && opt_mode == MODE_DECOMPRESS) {
@ -975,6 +969,10 @@ io_open_dest_real(file_pair *pair)
#endif #endif
return false; return false;
error:
free(pair->dest_name);
return true;
} }