Re: [PATCH maint] builtin-merge.c: fix memory under-allocation
- From
Shawn O. Pearce <spearce@spearce.org>
- Date
- Oct 9, 2008, 15:13 UTC
- Message-ID
- <20081009151300.GS8203@spearce.org>
- In-Reply-To
- <rKU9r5196P_JTKZZkb10yo7uwH_n_7KAuyX6RMOa9jc@cipher.nrlssc.navy.mil>
Brandon Casey <casey@nrlssc.navy.mil> wrote:
Show 12 quoted lines
> Junio C Hamano wrote: > > Brandon Casey <casey@nrlssc.navy.mil> writes: > >> I didn't mean to imply that the memory under-allocation > >> was caused by a change in variable type in this case. Re-reading my commit > >> message, maybe it sounds like that. > > > > Yeah, it does. I was scratching my head and had to read the patch three > > times until I got it (yes, I am especially slower than usual today, as the > > reason I am reading mails right now is because I am jetlagged and cannot > > sleep). > > If it's not too late, maybe this would make a better commit message:
Nope, I didn't get around to the patch until now. Better message is being used... ;-)
Thanks everyone.
Show 19 quoted lines
> --->8--- > builtin-merge.c: allocate correct amount of memory > > Fix two memory allocation errors which allocate space for a pointer rather > than enough space for the structure itself. > > This: > > struct commit_list *parent = xmalloc(sizeof(struct commit_list *)); > > should have been this: > > struct commit_list *parent = xmalloc(sizeof(struct commit_list)); > > But while we're at it, change the allocation to reference the variable it is > allocating memory for to try to prevent a similar mistake, for example if the > type is changed, in the future. > > Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
-- Shawn.