Commit Diff


commit - 5f989f2afdba9ad2b0d212417a547cf8e5e03bb76b628b6b779457315743a8ed
commit + 5b331784568bdf77ca345a7eaba3c88855a0e34e4996169d1fdb42e47b284eeb
blob - 99492fcf9ac56cc565a934ad3b3b0ac37f82f679aefb5d3f98805ec226505582
blob + 92f8395d98994e6ed809f9a1717dab0fe3d2e9e0bed2e6ea2f909ac0d2795b1c
--- lib/read_gotconfig_privsep.c	
+++ lib/read_gotconfig_privsep.c	
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdint.h>
+#include <string.h>
 #include <imsg.h>
 #include <sha1.h>
 #include <sha2.h>
@@ -49,8 +50,10 @@ got_gotconfig_read(struct got_gotconfig **conf, const 
 	int fd = -1;
 	int imsg_fds[2] = { -1, -1 };
 	pid_t pid;
-	struct imsgbuf *ibuf = NULL;
+	struct imsgbuf ibuf;
 
+	memset(&ibuf, 0, sizeof(ibuf));
+
 	*conf = calloc(1, sizeof(**conf));
 	if (*conf == NULL)
 		return got_error_from_errno("calloc");
@@ -63,12 +66,6 @@ got_gotconfig_read(struct got_gotconfig **conf, const 
 		goto done;
 	}
 
-	ibuf = calloc(1, sizeof(*ibuf));
-	if (ibuf == NULL) {
-		err = got_error_from_errno("calloc");
-		goto done;
-	}
-
 	if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) {
 		err = got_error_from_errno("socketpair");
 		goto done;
@@ -89,57 +86,57 @@ got_gotconfig_read(struct got_gotconfig **conf, const 
 		goto wait;
 	}
 	imsg_fds[1] = -1;
-	if (imsgbuf_init(ibuf, imsg_fds[0]) == -1) {
+	if (imsgbuf_init(&ibuf, imsg_fds[0]) == -1) {
 		err = got_error_from_errno("imsgbuf_init");
 		goto wait;
 	}
-	imsgbuf_allow_fdpass(ibuf);
+	imsgbuf_allow_fdpass(&ibuf);
 
-	err = got_privsep_send_gotconfig_parse_req(ibuf, fd);
+	err = got_privsep_send_gotconfig_parse_req(&ibuf, fd);
 	if (err)
 		goto wait;
 	fd = -1;
 
-	err = got_privsep_send_gotconfig_author_req(ibuf);
+	err = got_privsep_send_gotconfig_author_req(&ibuf);
 	if (err)
 		goto wait;
 
-	err = got_privsep_recv_gotconfig_str(&(*conf)->author, ibuf);
+	err = got_privsep_recv_gotconfig_str(&(*conf)->author, &ibuf);
 	if (err)
 		goto wait;
 
-	err = got_privsep_send_gotconfig_allowed_signers_req(ibuf);
+	err = got_privsep_send_gotconfig_allowed_signers_req(&ibuf);
 	if (err)
 		goto wait;
 
 	err = got_privsep_recv_gotconfig_str(&(*conf)->allowed_signers_file,
-	    ibuf);
+	    &ibuf);
 	if (err)
 		goto wait;
 
-	err = got_privsep_send_gotconfig_revoked_signers_req(ibuf);
+	err = got_privsep_send_gotconfig_revoked_signers_req(&ibuf);
 	if (err)
 		goto wait;
 
 	err = got_privsep_recv_gotconfig_str(&(*conf)->revoked_signers_file,
-	    ibuf);
+	    &ibuf);
 	if (err)
 		goto wait;
 
-	err = got_privsep_send_gotconfig_signer_id_req(ibuf);
+	err = got_privsep_send_gotconfig_signer_id_req(&ibuf);
 	if (err)
 		goto wait;
 
-	err = got_privsep_recv_gotconfig_str(&(*conf)->signer_id, ibuf);
+	err = got_privsep_recv_gotconfig_str(&(*conf)->signer_id, &ibuf);
 	if (err)
 		goto wait;
 
-	err = got_privsep_send_gotconfig_remotes_req(ibuf);
+	err = got_privsep_send_gotconfig_remotes_req(&ibuf);
 	if (err)
 		goto wait;
 
 	err = got_privsep_recv_gotconfig_remotes(&(*conf)->remotes,
-	    &(*conf)->nremotes, ibuf);
+	    &(*conf)->nremotes, &ibuf);
 	if (err)
 		goto wait;
 wait:
@@ -159,7 +156,7 @@ done:
 		got_gotconfig_free(*conf);
 		*conf = NULL;
 	}
-	imsgbuf_clear(ibuf);
-	free(ibuf);
+	if (ibuf.w)
+		imsgbuf_clear(&ibuf);
 	return err;
 }