From mboxrd@z Thu Jan 1 00:00:00 1970 From: john at keeping.me.uk (John Keeping) Date: Mon, 12 Oct 2015 21:29:29 +0100 Subject: [PATCH 1/2] ui-stats: free without condition In-Reply-To: <20151012202920.41c93924@leda.localdomain> References: <1444640375-13895-1-git-send-email-list@eworm.de> <20151012091012.GA19802@serenity.lan> <20151012111453.7eb07d73@leda.localdomain> <20151012202920.41c93924@leda.localdomain> Message-ID: <20151012202929.GC19802@serenity.lan> On Mon, Oct 12, 2015 at 08:29:20PM +0200, Christian Hesse wrote: > Christian Hesse on Mon, 2015/10/12 11:14: > > John Keeping on Mon, 2015/10/12 10:10: > > > On Mon, Oct 12, 2015 at 10:59:34AM +0200, Christian Hesse wrote: > > > > From: Christian Hesse > > > > > > > > xstrdup() returns allocated memory or NULL. It's safe to call free() > > > > without condition. > > > > > > > > Coverity-Id 13839 is kind of false posivtive, but this should fix it > > > > nevertheless. > > > > > > > > Coverity-Id: 13839 > > > > Signed-off-by: Christian Hesse > > > > --- > > > > ui-stats.c | 6 ++---- > > > > 1 file changed, 2 insertions(+), 4 deletions(-) > > > > > > This is wrong - we don't have strdup_strings set in the string_list so > > > it takes ownership of the pointer. The test on item->util is used as a > > > proxy testing if the entry is newly added to the list (in which case it > > > has taken ownership of the string) or not (in which case we must free > > > the string). > > > > My assumption was that string_list_insert() handles this itself and > > duplicates the string. Then please ignore the patches! :D > > Does it make sense to set > > authors.strdup_strings = 1; > items.strdup_strings = 1; > > and let string_list_insert() make the work? Personally, I'd say it's not worth the churn. I don't think Coverity is complaining about this anyway is it? The only problem I see in ui-stats.c is that we use item->util as a counter not a pointer. I'm not sure if casting it to uintptr_t will be enough to persuade Coverity that we know what we're doing.