Received: from eggs.gnu.org ([2001:4830:134:3::10]:34222) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YDzLD-00037r-Nx for qemu-devel@nongnu.org; Wed, 21 Jan 2015 12:45:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YDzLA-0003o6-QV for qemu-devel@nongnu.org; Wed, 21 Jan 2015 12:45:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58481) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YDzLA-0003o0-JR for qemu-devel@nongnu.org; Wed, 21 Jan 2015 12:45:16 -0500 From: Markus Armbruster References: <87bnlsl2qt.fsf@blackfin.pond.sub.org> <54BFB577.3080805@redhat.com> <87a91cchbt.fsf@blackfin.pond.sub.org> <54BFC17D.2060501@redhat.com> <87r3uo9l1i.fsf@blackfin.pond.sub.org> <54BFD24C.90400@redhat.com> Date: Wed, 21 Jan 2015 18:45:11 +0100 In-Reply-To: <54BFD24C.90400@redhat.com> (Paolo Bonzini's message of "Wed, 21 Jan 2015 17:22:36 +0100") Message-ID: <877fwg81ug.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] Can we make better use of Coverity? List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: peter.maydell@linaro.org, qemu-devel@nongnu.org Paolo Bonzini writes: > On 21/01/2015 17:05, Markus Armbruster wrote: >>>> >> What do you mean by "a GLib model"? scripts/coverity-model.c? >>> > >>> > Yes. It models g_malloc0 in a way that avoids a lot of false positives, >>> > but still is able to flag leaks. >> Understood. It's hugely better than nothing, > > Yes, I think between false positives and false negatives it affected > over 100 defects. Yes. RESOURCE_LEAK was pretty useless without it. >> but it still can't make >> Coverity see many relevant facts like GLib functions returning newly >> allocated storage. For that, you have to throw in a derived model, like >> I do. Unfortunately, the Scan service seems unable to do that. > > Right. You can also model the functions manually, like we do for > g_io_channel_unix_new: > > typedef struct _GIOChannel GIOChannel; > GIOChannel *g_io_channel_unix_new(int fd) > { > GIOChannel *c = g_malloc0(sizeof(GIOChannel)); > __coverity_escape__(fd); > return c; > } > > (This was done because of false positives when Coverity thought that fd > would leak at end of scope). > > If you know some offenders which did cause us to leak memory in the > past, please do submit a patch to scripts/coverity-model.c. Comparing two local scans, one with and one without my derived model, I think I can spot some gaps we could fill in coverity-model.c. Stay tuned... > BTW, thanks for starting this thread. We already have like 6 new users > who will be able to see the defects and fix them! That alone is very > much worthy! :) I hope regular scanning reports to qemu-devel will get us even more.