Always check returns from unlink()

This commit is contained in:
Andrea Shepard
2014-03-18 17:52:31 -07:00
committed by Nick Mathewson
parent df076eccfa
commit abdf1878a3
6 changed files with 59 additions and 13 deletions
+8 -1
View File
@@ -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)) {