plug memory leaks in error paths while collecting log messages
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
diff --git a/got/got.c b/got/got.c
index 47edd67..f09b051 100644
--- a/got/got.c
+++ b/got/got.c
@@ -512,6 +512,10 @@ done:
if (fd != -1 && close(fd) == -1 && err == NULL)
err = got_error_from_errno2("close", *logmsg_path);
free(initial_content);
+ if (err) {
+ free(*logmsg_path);
+ *logmsg_path = NULL;
+ }
return err;
}
@@ -5727,12 +5731,11 @@ done:
err = got_error_from_errno2("close", *tagmsg_path);
/* Editor is done; we can now apply unveil(2) */
- if (err == NULL) {
+ if (err == NULL)
err = apply_unveil(repo_path, 0, NULL);
- if (err) {
- free(*tagmsg);
- *tagmsg = NULL;
- }
+ if (err) {
+ free(*tagmsg);
+ *tagmsg = NULL;
}
return err;
}
@@ -6607,12 +6610,11 @@ done:
err = got_error_from_errno2("close", a->logmsg_path);
/* Editor is done; we can now apply unveil(2) */
- if (err == NULL) {
+ if (err == NULL)
err = apply_unveil(a->repo_path, 0, a->worktree_path);
- if (err) {
- free(*logmsg);
- *logmsg = NULL;
- }
+ if (err) {
+ free(*logmsg);
+ *logmsg = NULL;
}
return err;
}