# [PATCH] packfile: release bad_objects in close_pack()

2 messages from 2021-09-24 to 2021-09-24. Participants: René Scharfe, Jeff King.
Thread: https://gitlist.dev/t/56577

## René Scharfe, 2021-09-24 06:10

Subject: [PATCH] packfile: release bad_objects in close_pack()
Message-ID: <33a0120b-c10d-2709-49d3-7c3dc26565ee@web.de>
URL: https://gitlist.dev/e/33a0120b-c10d-2709-49d3-7c3dc26565ee%40web.de

```
Unusable entries of a damaged pack file are recorded in the oidset
bad_objects.  Release it when we're done with the pack.

This doesn't affect intact packs because an empty oidset requires
no allocation.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 packfile.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/packfile.c b/packfile.c
index 0e92bd7bd2..89402cfc69 100644
--- a/packfile.c
+++ b/packfile.c
@@ -339,6 +339,7 @@ void close_pack(struct packed_git *p)
 	close_pack_fd(p);
 	close_pack_index(p);
 	close_pack_revindex(p);
+	oidset_clear(&p->bad_objects);
 }

 void close_object_store(struct raw_object_store *o)
--
2.33.0

```

## Jeff King, 2021-09-24 20:21

Subject: Re: [PATCH] packfile: release bad_objects in close_pack()
Message-ID: <YU4zMj76HXP5PhCu@coredump.intra.peff.net>
URL: https://gitlist.dev/e/YU4zMj76HXP5PhCu%40coredump.intra.peff.net
In-Reply-To: <33a0120b-c10d-2709-49d3-7c3dc26565ee@web.de>

```
On Fri, Sep 24, 2021 at 08:10:10AM +0200, René Scharfe wrote:

> Unusable entries of a damaged pack file are recorded in the oidset
> bad_objects.  Release it when we're done with the pack.
> 
> This doesn't affect intact packs because an empty oidset requires
> no allocation.

Good catch. I wondered if this was related to your recent 09ef66179b
(packfile: use oidset for bad objects, 2021-09-11), but we'd have just
leaked the manual array before then.

> diff --git a/packfile.c b/packfile.c
> index 0e92bd7bd2..89402cfc69 100644
> --- a/packfile.c
> +++ b/packfile.c
> @@ -339,6 +339,7 @@ void close_pack(struct packed_git *p)
>  	close_pack_fd(p);
>  	close_pack_index(p);
>  	close_pack_revindex(p);
> +	oidset_clear(&p->bad_objects);
>  }

Looks obviously correct.

-Peff

```
