From: Junio C Hamano Date: Thu, 29 Dec 2022 07:12:59 GMT Subject: Re: [PATCH 09/20] name-rev: don't xstrdup() an already dup'd string Message-ID: In-Reply-To: René Scharfe writes: >> - 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.