Commit 8347f8e796a6f59deaf6f75275ae6e3d730fce9f

Stefan Sperling 2021-10-15T17:17:52

plug memory leak in an error path of read_packed_object()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
diff --git a/libexec/got-index-pack/got-index-pack.c b/libexec/got-index-pack/got-index-pack.c
index 5c97abb..bd07835 100644
--- a/libexec/got-index-pack/got-index-pack.c
+++ b/libexec/got-index-pack/got-index-pack.c
@@ -255,8 +255,11 @@ read_packed_object(struct got_pack *pack, struct got_indexed_object *obj,
 		SHA1Update(&ctx, header, headerlen);
 		if (obj->size > GOT_DELTA_RESULT_SIZE_CACHED_MAX) {
 			err = read_file_sha1(&ctx, tmpfile, datalen);
-			if (err)
+			if (err) {
+				free(header);
+				free(data);
 				break;
+			}
 		} else
 			SHA1Update(&ctx, data, datalen);
 		SHA1Final(obj->id.sha1, &ctx);