Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4234328imm; Mon, 8 Oct 2018 17:56:41 -0700 (PDT) X-Google-Smtp-Source: ACcGV61InMQ1sXIk3FKcuP1ZuVIOVmKmPRyIl62UVnhkDhDGK2qhNGWHcpyKnLlEWeDk85U9GVD2 X-Received: by 2002:a62:6143:: with SMTP id v64-v6mr21640074pfb.125.1539046601007; Mon, 08 Oct 2018 17:56:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539046600; cv=none; d=google.com; s=arc-20160816; b=X+u+Z6BQPndRTz+v1k39tNKFwcastAQEAj9PNAp5aJh97YwRSUZ+64hd91Oa1qjHXK Iz/oEVbpe3kSUFxFbk+jbSFX2aJTghWohJByatHnrlKixAyBZdjnw5Qs9N2Q+I54LGH2 jTUhs0caMiQHN9lF87edTvADJzDlO/GAx7sCKsteGurnd/tiCdhK3E6Xt02bOzFxVcuG /uVr/9W+cPyHqLZdvIe9AlZUa/kJJLoyX/foEry03bg7nnyEa/RhaqXI4kEHb4t7VWN4 Zt7bSGK8YLo49+1KS+28wrDwmU7/ZGnWO7x5Z2laFVGnyPyGCrnR5WqnY+4SiqnFu3Yz VUfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=lO0JN750HKUfhheA67yTqH2n0UYvOW+bNm5QDAR3kn4=; b=tXwQKKDs2cHuVlMQOPk36KSOFgZjQF7pEu1JDp71bK9La0XQQBoDGlMDmkNuIFC8Uq dd03c6bc4WEK3vu2bd6Qd/OQNGSPRDMtXxeXU3um3gmae4QxlZMJjcEo1rcc9LQ+hVXz INX/enAw1XDZfGA8Wk5QVqH8vDc59KP4BKzvx7nT1Jv1jUHVUkNhznIjcBrrhDEmitNI oTT4Hn20sMmB7oSu1R3JxlnR6IxNcW5B/dFbc5gG59DjlkORWlqw2V57s1yViwxugUxc c8cAF2LvJTtjjD0lKyIe70ksxVHPGt11swMTlD3Kkv1xc8MWsuxRGMmfAeAeLiG+rIcV neYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RKCFwDUs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g84-v6si2022240pfd.86.2018.10.08.17.56.26; Mon, 08 Oct 2018 17:56:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RKCFwDUs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726967AbeJIIJd (ORCPT + 99 others); Tue, 9 Oct 2018 04:09:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:42218 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726786AbeJIIJb (ORCPT ); Tue, 9 Oct 2018 04:09:31 -0400 Received: from jouet.infradead.org (unknown [179.97.41.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5FF12214C2; Tue, 9 Oct 2018 00:55:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539046510; bh=aGROLRvqINZNUeItfmAfnvxOhR2gc3Dv3tuBQzpSWjY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RKCFwDUsKUqIgUPtdM/lzRLyfswFdDRzL34ZEx7jHqAcvJIbVUAuns8+etlUeDPvw vjny/q+0VNnKEt8Hg3a7G+4GPCPGMC46dnWSCPO8FodTXp0hm0EKD98K++C8qcSxF7 nL+skEz/BrPl/sZ8jWcF9eiXyJNnzzuU1tGQb/Uc= From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Sanskriti Sharma , Joe Lawrence , Arnaldo Carvalho de Melo Subject: [PATCH 07/12] perf tools: Avoid double free in read_event_file() Date: Mon, 8 Oct 2018 21:54:22 -0300 Message-Id: <20181009005427.6607-8-acme@kernel.org> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20181009005427.6607-1-acme@kernel.org> References: <20181009005427.6607-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sanskriti Sharma The temporary 'buf' buffer allocated in read_event_file() may be freed twice. Move the free() call to the common function exit point. Fixes the following coverity complaints: Error: USE_AFTER_FREE (CWE-825): tools/perf/util/trace-event-read.c:309: double_free: Calling "free" frees pointer "buf" which has already been freed. Signed-off-by: Sanskriti Sharma Reviewed-by: Jiri Olsa Cc: Joe Lawrence Link: http://lkml.kernel.org/r/1538490554-8161-5-git-send-email-sansharm@redhat.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/trace-event-read.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c index b98ee2a2eb44..a278e1eee5f5 100644 --- a/tools/perf/util/trace-event-read.c +++ b/tools/perf/util/trace-event-read.c @@ -297,10 +297,8 @@ static int read_event_file(struct tep_handle *pevent, char *sys, } ret = do_read(buf, size); - if (ret < 0) { - free(buf); + if (ret < 0) goto out; - } ret = parse_event_file(pevent, buf, size, sys); if (ret < 0) -- 2.14.4