commit - 50b0790ed9a28fced631f31e5b7ca76a9a610ea5
commit + 97972933210f224479bf2e8f44c4cb88a2dec393
blob - da2b1166ac33d3f36f0666ef6026f72a8c51cbcc
blob + 47edd6740e291c0126563b4b3e27ef5aed14614a
--- got/got.c
+++ got/got.c
char *initial_content = NULL;
const struct got_error *err = NULL;
int initial_content_len;
- int fd;
+ int fd = -1;
initial_content_len = asprintf(&initial_content,
"\n# %s to be imported to branch %s\n", path_dir,
if (err)
goto done;
- write(fd, initial_content, initial_content_len);
- close(fd);
+ if (write(fd, initial_content, initial_content_len) == -1) {
+ err = got_error_from_errno2("write", *logmsg_path);
+ goto done;
+ }
err = edit_logmsg(logmsg, editor, *logmsg_path, initial_content);
done:
+ if (fd != -1 && close(fd) == -1 && err == NULL)
+ err = got_error_from_errno2("close", *logmsg_path);
free(initial_content);
return err;
}
if (err)
goto done;
- write(fd, initial_content, initial_content_len);
- close(fd);
+ if (write(fd, initial_content, initial_content_len) == -1) {
+ err = got_error_from_errno2("write", *tagmsg_path);
+ goto done;
+ }
err = get_editor(&editor);
if (err)
free(template);
free(editor);
+ if (fd != -1 && close(fd) == -1 && err == NULL)
+ err = got_error_from_errno2("close", *tagmsg_path);
+
/* Editor is done; we can now apply unveil(2) */
if (err == NULL) {
err = apply_unveil(repo_path, 0, NULL);
char *template = NULL;
struct collect_commit_logmsg_arg *a = arg;
int initial_content_len;
- int fd;
+ int fd = -1;
size_t len;
/* if a message was specified on the command line, just use it */
if (err)
goto done;
- write(fd, initial_content, initial_content_len);
+ if (write(fd, initial_content, initial_content_len) == -1) {
+ err = got_error_from_errno2("write", a->logmsg_path);
+ goto done;
+ }
TAILQ_FOREACH(pe, commitable_paths, entry) {
struct got_commitable *ct = pe->data;
got_commitable_get_status(ct),
got_commitable_get_path(ct));
}
- close(fd);
err = edit_logmsg(logmsg, a->editor, a->logmsg_path, initial_content);
done:
free(initial_content);
free(template);
+ if (fd != -1 && close(fd) == -1 && err == NULL)
+ err = got_error_from_errno2("close", a->logmsg_path);
+
/* Editor is done; we can now apply unveil(2) */
if (err == NULL) {
err = apply_unveil(a->repo_path, 0, a->worktree_path);