plug leaks in error paths of got_privsep_send_tree()
diff --git a/lib/privsep.c b/lib/privsep.c
index 8d611b1..72b117b 100644
--- a/lib/privsep.c
+++ b/lib/privsep.c
@@ -734,19 +734,22 @@ got_privsep_send_tree(struct imsgbuf *ibuf, struct got_pathlist_head *entries,
return got_error_from_errno("imsg_create TREE_ENTRY");
/* Keep in sync with struct got_imsg_tree_object definition! */
- if (imsg_add(wbuf, pte->id, SHA1_DIGEST_LENGTH) == -1)
+ if (imsg_add(wbuf, pte->id, SHA1_DIGEST_LENGTH) == -1) {
err = got_error_from_errno("imsg_add TREE_ENTRY");
- if (err)
+ ibuf_free(wbuf);
return err;
- if (imsg_add(wbuf, &pte->mode, sizeof(pte->mode)) == -1)
+ }
+ if (imsg_add(wbuf, &pte->mode, sizeof(pte->mode)) == -1) {
err = got_error_from_errno("imsg_add TREE_ENTRY");
- if (err)
+ ibuf_free(wbuf);
return err;
+ }
- if (imsg_add(wbuf, name, namelen) == -1)
+ if (imsg_add(wbuf, name, namelen) == -1) {
err = got_error_from_errno("imsg_add TREE_ENTRY");
- if (err)
+ ibuf_free(wbuf);
return err;
+ }
wbuf->fd = -1;
imsg_close(ibuf, wbuf);