shithub: git9

Download patch

ref: 5103093b16048b4ecaa8159fb76e43cfb3bebf09
parent: 0846b8a3b18ee30f648f26f48dca20e83aaf672b
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Oct 24 20:07:51 EDT 2020

packfiles: Bterm only once (thanks jspreis)

We were crashing because we were closing the bfd
twice, and creating a corrupt object. This solves
the problem.

--- a/pack.c
+++ b/pack.c
@@ -871,7 +871,7 @@
 	snprint(path, sizeof(path), ".git/objects/%c%c/%s", hbuf[0], hbuf[1], hbuf + 2);
 	if((f = Bopen(path, OREAD)) != nil){
 		if(readloose(f, obj, flag) == -1)
-			goto error;
+			goto errorf;
 		Bterm(f);
 		parseobject(obj);
 		cache(obj);
@@ -904,17 +904,17 @@
 	if((f = Bopen(path, OREAD)) == nil)
 		goto error;
 	if(Bseek(f, o, 0) == -1)
-		goto error;
+		goto errorf;
 	if(readpacked(f, obj, flag) == -1)
-		goto error;
+		goto errorf;
 	Bterm(f);
 	parseobject(obj);
 	free(d);
 	cache(obj);
 	return obj;
+errorf:
+	Bterm(f);
 error:
-	if(f != nil)
-		Bterm(f);
 	free(d);
 	free(new);
 	return nil;
@@ -1092,7 +1092,6 @@
 		hwrite(f, o->hash.h, sizeof(o->hash.h), &st);
 	}
 
-	/* fuck it, pointless */
 	for(i = 0; i < nobj; i++){
 		PUTBE32(buf, objects[i]->crc);
 		hwrite(f, buf, 4, &st);