Re: [PATCH] factorize pack structure allocation
Show 24 quoted lines
> New pack structures are currently allocated in 2 different places
> and all members have to be initialized explicitly. This is prone
> to errors leading to segmentation faults as found by Teemu Likonen.
>
> Let's have a common place where this structure is allocated, and have
> all members implicitly initialized to zero.
>
> Signed-off-by: Nicolas Pitre <nico@cam.org>
> ---
> diff --git a/sha1_file.c b/sha1_file.c
> index a92f023..c56f674 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -792,18 +792,28 @@ unsigned char* use_pack(struct packed_git *p,
> return win->base + offset;
> }
>
> +static struct packed_git *alloc_packed_git(int extra)
> +{
> + struct packed_git *p = xmalloc(sizeof(*p) + extra);
> + memset(p, 0, sizeof(*p));
> + p->pack_fd = -1;
> + return p;
> +}Nit: That's an explicit 0 initialization!
jdl