mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Always check returns from unlink()
This commit is contained in:
committed by
Nick Mathewson
parent
df076eccfa
commit
abdf1878a3
+8
-1
@@ -2141,6 +2141,7 @@ static int
|
||||
finish_writing_to_file_impl(open_file_t *file_data, int abort_write)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
tor_assert(file_data && file_data->filename);
|
||||
if (file_data->stdio_file) {
|
||||
if (fclose(file_data->stdio_file)) {
|
||||
@@ -2157,7 +2158,13 @@ finish_writing_to_file_impl(open_file_t *file_data, int abort_write)
|
||||
if (file_data->rename_on_close) {
|
||||
tor_assert(file_data->tempname && file_data->filename);
|
||||
if (abort_write) {
|
||||
unlink(file_data->tempname);
|
||||
int res = unlink(file_data->tempname);
|
||||
if (res != 0) {
|
||||
/* We couldn't unlink and we'll leave a mess behind */
|
||||
log_warn(LD_FS, "Failed to unlink %s: %s",
|
||||
file_data->tempname, strerror(errno));
|
||||
r = -1;
|
||||
}
|
||||
} else {
|
||||
tor_assert(strcmp(file_data->filename, file_data->tempname));
|
||||
if (replace_file(file_data->tempname, file_data->filename)) {
|
||||
|
||||
Reference in New Issue
Block a user