Commit Diff


commit - eb81bc23c735e8aa9eaee796a230c7d7c76657ba
commit + ce7556f23f6b599e1f224216af82b0a097a13ca3
blob - 08567c76e72993115d4c0a7bc0b81b68a0d881fe
blob + a2fb22ffb05d1bb22133d52b772caf2c5120b1e8
--- lib/object.c
+++ lib/object.c
@@ -1352,7 +1352,7 @@ open_blob(struct got_blob_object **blob, struct got_re
 {
 	const struct got_error *err = NULL;
 	struct got_packidx *packidx = NULL;
-	int idx;
+	int idx, dfd = -1;
 	char *path_packfile = NULL;
 	uint8_t *outbuf;
 	size_t size, hdrlen;
@@ -1419,14 +1419,20 @@ open_blob(struct got_blob_object **blob, struct got_re
 
 		if (sb.st_size != size) {
 			err = got_error(GOT_ERR_PRIVSEP_LEN);
+			goto done;
+		}
+
+		dfd = dup(outfd);
+		if (dfd == -1) {
+			err = got_error_from_errno("dup");
 			goto done;
 		}
 
 		(*blob)->f = fdopen(outfd, "rb");
 		if ((*blob)->f == NULL) {
 			err = got_error_from_errno("fdopen");
-			close(outfd);
-			outfd = -1;
+			close(dfd);
+			dfd = -1;
 			goto done;
 		}
 	}