Commit Diff


commit - cee3836880940ba0d1203e0682a43a680132bc27
commit + 66993e5902f3e39980a0dada0946e146008a35c5
blob - e95ba2936e96e58c1f16c13b3a81b482f35d02a4
blob + a51a450a06ab2800d2fe4a200fc31cc59364dac6
--- got/got.c
+++ got/got.c
@@ -516,8 +516,13 @@ collect_import_msg(char **logmsg, char **logmsg_path, 
 
 	if (write(fd, initial_content, initial_content_len) == -1) {
 		err = got_error_from_errno2("write", *logmsg_path);
+		goto done;
+	}
+	if (close(fd) == -1) {
+		err = got_error_from_errno2("close", *logmsg_path);
 		goto done;
 	}
+	fd = -1;
 
 	err = edit_logmsg(logmsg, editor, *logmsg_path, initial_content,
 	    initial_content_len, 1);
@@ -7405,8 +7410,13 @@ get_tag_message(char **tagmsg, char **tagmsg_path, con
 
 	if (write(fd, initial_content, initial_content_len) == -1) {
 		err = got_error_from_errno2("write", *tagmsg_path);
+		goto done;
+	}
+	if (close(fd) == -1) {
+		err = got_error_from_errno2("close", *tagmsg_path);
 		goto done;
 	}
+	fd = -1;
 
 	err = get_editor(&editor);
 	if (err)
@@ -8912,6 +8922,12 @@ collect_commit_logmsg(struct got_pathlist_head *commit
 		    diff_path);
 	}
 
+	if (close(fd) == -1) {
+		err = got_error_from_errno2("close", a->logmsg_path);
+		goto done;
+	}
+	fd = -1;
+
 	err = edit_logmsg(logmsg, a->editor, a->logmsg_path, initial_content,
 	    initial_content_len, a->prepared_log ? 0 : 1);
 done:
@@ -11661,7 +11677,7 @@ histedit_edit_logmsg(struct got_histedit_list_entry *h
 	const struct got_error *err = NULL;
 	struct got_commit_object *commit = NULL;
 	int logmsg_len;
-	int fd;
+	int fd = -1;
 	struct got_histedit_list_entry *folded = NULL;
 
 	err = got_object_open_as_commit(&commit, repo, hle->commit_id);
@@ -11710,8 +11726,15 @@ histedit_edit_logmsg(struct got_histedit_list_entry *h
 	if (err)
 		goto done;
 
-	write(fd, logmsg, logmsg_len);
-	close(fd);
+	if (write(fd, logmsg, logmsg_len) == -1) {
+		err = got_error_from_errno2("write", logmsg_path);
+		goto done;
+	}
+	if (close(fd) == -1) {
+		err = got_error_from_errno2("close", logmsg_path);
+		goto done;
+	}
+	fd = -1;
 
 	err = get_editor(&editor);
 	if (err)
@@ -11728,6 +11751,8 @@ histedit_edit_logmsg(struct got_histedit_list_entry *h
 			err = got_error_from_errno("strdup");
 	}
 done:
+	if (fd != -1 && close(fd) == -1 && err == NULL)
+		err = got_error_from_errno2("close", logmsg_path);
 	if (logmsg_path && unlink(logmsg_path) != 0 && err == NULL)
 		err = got_error_from_errno2("unlink", logmsg_path);
 	free(logmsg_path);