factorize imsg_clear calls after imsg_flush failures imsg_clear frees and closes resources allocated as part of enqueueing imsgs so it's a no-op after reads. discussed with and ok stsp@
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
diff --git a/lib/fetch.c b/lib/fetch.c
index 66bbb44..e557ed1 100644
--- a/lib/fetch.c
+++ b/lib/fetch.c
@@ -476,7 +476,6 @@ got_fetch_pack(struct got_object_id **pack_hash, struct got_pathlist_head *refs,
if (err)
break;
}
- imsg_clear(&idxibuf);
}
if (close(imsg_idxfds[0]) == -1) {
err = got_error_from_errno("close");
diff --git a/lib/gotconfig.c b/lib/gotconfig.c
index 664f170..ab88498 100644
--- a/lib/gotconfig.c
+++ b/lib/gotconfig.c
@@ -108,7 +108,6 @@ got_gotconfig_read(struct got_gotconfig **conf, const char *gotconfig_path)
if (err)
goto done;
- imsg_clear(ibuf);
err = got_privsep_send_stop(imsg_fds[0]);
child_err = got_privsep_wait_for_child(pid);
if (child_err && err == NULL)
diff --git a/lib/pack.c b/lib/pack.c
index c981da3..b807943 100644
--- a/lib/pack.c
+++ b/lib/pack.c
@@ -727,7 +727,6 @@ pack_stop_privsep_child(struct got_pack *pack)
err = got_privsep_wait_for_child(pack->privsep_child->pid);
if (close(pack->privsep_child->imsg_fd) == -1 && err == NULL)
err = got_error_from_errno("close");
- imsg_clear(pack->privsep_child->ibuf);
free(pack->privsep_child->ibuf);
free(pack->privsep_child);
pack->privsep_child = NULL;
diff --git a/lib/privsep.c b/lib/privsep.c
index 48e50b6..4cbc40e 100644
--- a/lib/privsep.c
+++ b/lib/privsep.c
@@ -208,6 +208,7 @@ got_privsep_send_error(struct imsgbuf *ibuf, const struct got_error *err)
if (ret == -1) {
fprintf(stderr, "%s: error %d \"%s\": imsg_flush: %s\n",
getprogname(), err->code, err->msg, strerror(errno));
+ imsg_clear(ibuf);
return;
}
}
@@ -221,8 +222,10 @@ flush_imsg(struct imsgbuf *ibuf)
if (err)
return err;
- if (imsg_flush(ibuf) == -1)
+ if (imsg_flush(ibuf) == -1) {
+ imsg_clear(ibuf);
return got_error_from_errno("imsg_flush");
+ }
return NULL;
}
@@ -245,7 +248,6 @@ got_privsep_send_stop(int fd)
return got_error_from_errno("imsg_compose STOP");
err = flush_imsg(&ibuf);
- imsg_clear(&ibuf);
return err;
}
diff --git a/lib/repository.c b/lib/repository.c
index 255d035..5260575 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -577,7 +577,6 @@ parse_gitconfig_file(int *gitconfig_repository_format_version,
goto done;
}
- imsg_clear(ibuf);
err = got_privsep_send_stop(imsg_fds[0]);
child_err = got_privsep_wait_for_child(pid);
if (child_err && err == NULL)
diff --git a/lib/repository_admin.c b/lib/repository_admin.c
index 422da92..c1adcc4 100644
--- a/lib/repository_admin.c
+++ b/lib/repository_admin.c
@@ -387,7 +387,6 @@ got_repo_index_pack(FILE *packfile, struct got_object_id *pack_hash,
if (err)
break;
}
- imsg_clear(&idxibuf);
}
if (close(imsg_idxfds[0]) == -1) {
err = got_error_from_errno("close");