Re: [PATCH 09/20] name-rev: don't xstrdup() an already dup'd string
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Dec 29, 2022, 07:12 UTC
- Message-ID
- <xmqqv8lun0n8.fsf@gitster.g>
- In-Reply-To
- <dbc7c55d-d546-d004-ef44-62bd7349d5c9@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 7 quoted lines
>> - tip_table.table[tip_table.nr].refname = xstrdup(refname); >> + tip_table.table[tip_table.nr].refname = shorten_unambiguous ? refname : >> + xstrdup(refname); > > Hmm, this works based on knowledge about the inner workings of > name_ref_abbrev(), which provides the refname. Could be cleaned up by > inlining that short function, or by moving the xstrdup() call there.
Yeah, name_ref_abbrev() returns sometimes an allocated and some other times a borrowed piece of memory, which is a poor design that ignores memory ownership issues. Luckily the function being touched is the sole caller of it, and I agree with you that inlining may give us a better fix.