Subject: Re: [PATCH v4 12/27] object-file: mark cached object buffers as const

From: Patrick Steinhardt <[email-masked]>
Date: Fri, 7 Jun 2024 06:52:23 +0200

On Thu, Jun 06, 2024 at 09:25:20AM -0700, Junio C Hamano wrote:
> Junio C Hamano <[email-masked]> writes:
> 
> > Indeed, that seems to be the case.  With the attached at the tip of
> > the branch and rebuilding 'seen' seems to pass these 6130, 7010, 8002
> > tests with SANTIZE=leak.
> >
> > From f307bbf7bd317d90db29bd1589b49e84b9e37e88 Mon Sep 17 00:00:00 2001
> > From: Junio C Hamano <[email-masked]>
> > Date: Wed, 5 Jun 2024 23:03:34 -0700
> > Subject: [PATCH] fixup! object-file: mark cached object buffers as const
> >
> > ---
> >  object-file.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/object-file.c b/object-file.c
> > index b5b5a59dc6..2d5bd3a211 100644
> > --- a/object-file.c
> > +++ b/object-file.c
> > @@ -1785,8 +1785,10 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
> >  
> >  	hash_object_file(the_hash_algo, buf, len, type, oid);
> >  	if (repo_has_object_file_with_flags(the_repository, oid, OBJECT_INFO_QUICK | OBJECT_INFO_SKIP_FETCH_OBJECT) ||
> > -	    find_cached_object(oid))
> > +	    find_cached_object(oid)) {
> > +		free(co_buf);
> >  		return 0;
> > +	}
> >  	ALLOC_GROW(cached_objects, cached_object_nr + 1, cached_object_alloc);
> >  	co = &cached_objects[cached_object_nr++];
> >  	co->size = len;
> 
> Wait.  Why do we need to allocate co_buf that early in the first
> place?  IOW, shouldn't the fixup be more like this?

That is of course the much more elegant solution here. Will adapt.

Patrick