Commit Diff


commit - 13cebc62497c5f3b3bfb884c834ebc63ac9be4040bd5dbc4ce1dd586700ba988
commit + a0c2847a9593249567d340ae77cba1cccc55782452be20fc8b842b05fc6a1b43
blob - fdf71500ac9ae3848dc014cbe7ce67b9b80365d771cec64378c04f711e654c69
blob + 52aea231f780af0e74fde0abc67501db94a91a8caeeb9dc82229a1c3545e67ff
--- libexec/got-read-blob/got-read-blob.c	
+++ libexec/got-read-blob/got-read-blob.c	
@@ -78,7 +78,7 @@ main(int argc, char *argv[])
 	for (;;) {
 		struct imsg imsg, imsg_outfd;
 		FILE *f = NULL;
-		int fd = -1, outfd = -1;
+		int fd = -1, outfd = -1, finished = 0;
 		size_t size;
 		struct got_object *obj = NULL;
 		uint8_t *buf = NULL;
@@ -102,9 +102,12 @@ main(int argc, char *argv[])
 			break;
 		}
 
-		if (imsg.hdr.type == GOT_IMSG_STOP)
-			break;
+		if (imsg.hdr.type == GOT_IMSG_STOP) {
+			finished = 1;
+			goto done;
+		}
 
+
 		if (imsg.hdr.type != GOT_IMSG_BLOB_REQUEST) {
 			err = got_error(GOT_ERR_PRIVSEP_MSG);
 			goto done;
@@ -202,9 +205,12 @@ done:
 
 		imsg_free(&imsg);
 		imsg_free(&imsg_outfd);
-		if (obj)
+		if (obj) {
 			got_object_close(obj);
-		if (err)
+			obj = NULL;
+		}
+
+		if (err || finished)
 			break;
 	}
 
blob - 2d68d8873e758c6d2e4b9ca742d079a71274669ddc72f93b0e2b9b2fb61bfd5a
blob + 8400669bd5450aacf6bd5f3a92fa35c5b544561940258f313f6da04ccbffd4ef
--- libexec/got-read-gitconfig/got-read-gitconfig.c	
+++ libexec/got-read-gitconfig/got-read-gitconfig.c	
@@ -365,7 +365,7 @@ main(int argc, char *argv[])
 
 	for (;;) {
 		struct imsg imsg;
-		int fd = -1;
+		int fd = -1, finished = 0;
 
 		memset(&imsg, 0, sizeof(imsg));
 
@@ -381,8 +381,10 @@ main(int argc, char *argv[])
 			break;
 		}
 
-		if (imsg.hdr.type == GOT_IMSG_STOP)
-			break;
+		if (imsg.hdr.type == GOT_IMSG_STOP) {
+			finished = 1;
+			goto done;
+		}
 
 		switch (imsg.hdr.type) {
 		case GOT_IMSG_GITCONFIG_PARSE_REQUEST:
@@ -427,13 +429,14 @@ main(int argc, char *argv[])
 			break;
 		}
 
+	done:
 		if (fd != -1) {
 			if (close(fd) == -1 && err == NULL)
 				err = got_error_from_errno("close");
 		}
 
 		imsg_free(&imsg);
-		if (err)
+		if (err || finished)
 			break;
 	}
 
blob - 11c0d5e6eae4bd74aef4da3973706cc764649fc7b5bc209c07ffbcd32a595386
blob + 7e6b72bc44ea8a96a55e06b6d5016385e6b4fb6ab65fc9ee1314633479f9051c
--- libexec/got-read-gotconfig/got-read-gotconfig.c	
+++ libexec/got-read-gotconfig/got-read-gotconfig.c	
@@ -513,7 +513,7 @@ main(int argc, char *argv[])
 
 	for (;;) {
 		struct imsg imsg;
-		int fd = -1;
+		int fd = -1, finished = 0;
 
 		memset(&imsg, 0, sizeof(imsg));
 
@@ -529,8 +529,10 @@ main(int argc, char *argv[])
 			break;
 		}
 
-		if (imsg.hdr.type == GOT_IMSG_STOP)
-			break;
+		if (imsg.hdr.type == GOT_IMSG_STOP) {
+			finished = 1;
+			goto done;
+		}
 
 		switch (imsg.hdr.type) {
 		case GOT_IMSG_GOTCONFIG_PARSE_REQUEST:
@@ -598,14 +600,14 @@ main(int argc, char *argv[])
 			err = got_error(GOT_ERR_PRIVSEP_MSG);
 			break;
 		}
-
+	done:
 		if (fd != -1) {
 			if (close(fd) == -1 && err == NULL)
 				err = got_error_from_errno("close");
 		}
 
 		imsg_free(&imsg);
-		if (err)
+		if (err || finished)
 			break;
 	}
 
blob - cd10c8a90f5478a7a13d713d404a5a810c8f389f548e7b8d32146a8da2c07075
blob + 780b4a00a2500628ba1b159fd00cc0cefb0abac0f786ff464a314187c8b016da
--- libexec/got-read-object/got-read-object.c	
+++ libexec/got-read-object/got-read-object.c	
@@ -116,7 +116,7 @@ main(int argc, char *argv[])
 #endif
 
 	for (;;) {
-		int fd = -1, outfd = -1;
+		int fd = -1, outfd = -1, finished = 0;
 
 		if (sigint_received) {
 			err = got_error(GOT_ERR_CANCELLED);
@@ -130,8 +130,10 @@ main(int argc, char *argv[])
 			break;
 		}
 
-		if (imsg.hdr.type == GOT_IMSG_STOP)
-			break;
+		if (imsg.hdr.type == GOT_IMSG_STOP) {
+			finished = 1;
+			goto done;
+		}
 
 		if (imsg.hdr.type != GOT_IMSG_OBJECT_REQUEST &&
 		    imsg.hdr.type != GOT_IMSG_RAW_OBJECT_REQUEST) {
@@ -203,9 +205,11 @@ done:
 		if (fd != -1 && close(fd) == -1 && err == NULL)
 			err = got_error_from_errno("close");
 		imsg_free(&imsg);
-		if (obj)
+		if (obj) {
 			got_object_close(obj);
-		if (err)
+			obj = NULL;
+		}
+		if (err || finished)
 			break;
 	}