Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3429906ioo; Mon, 30 May 2022 01:44:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqe+QpCseo+bC98FdiiPC8j9XUE6ttuxn5joA862EoRqNFyO3IdyOY90hY1hYfF+32cG6G X-Received: by 2002:a05:6402:1f0d:b0:42a:edb1:c4c with SMTP id b13-20020a0564021f0d00b0042aedb10c4cmr58346918edb.204.1653900297475; Mon, 30 May 2022 01:44:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653900297; cv=none; d=google.com; s=arc-20160816; b=l7Deie5VPo0sJG5Nbg81KILi26O3gjOoa8l5xW0ZjyNZFGl6XRA/J1ht1d9XI+S6xz 7+rBBs55bhRP7YkQxarMec7jk9DRnSYkuDEo4dQNlK4yFPWSefcF3SaXnDMqdS4LHtLr 60FHplANOzyW55NlrFlyE4FzNOT2ac/G2KcqfxeODpgMH+aISt7KKo5XBjUnvpByb2hG mRb4WuluzGV9kcjIYvW6GSoT2BPfmI3IAp5uF8ZCXR1/HMxxt1dHmGhqzLPfLNvCQwMJ VGhP385svKpXQH095JV5iFpkgmKkP6bidJG7z1E366w1cwbpwMDt5JET16L6MPsk5FX8 wh6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=yFVo55Koj86euIi/CfkP3yhjrZ0w03FCq+gj53Do3GM=; b=NGFHPTQGPhoKA3JRrC/BznBXQTMA5zpHOaf0SYrhAY/dYTTJmA4OITO87rPKcQDTWk 8Ak6m4hsEzGrWOFR0rahbvmLSTcVUhDODPyU741+Q33/K+Pz/SHwXmVnctUEIYHbLVnC l2CiRR8tqgvg6OVOWI6XWC/iX/25QtbfgpP3CEAHOF86f/bObRslJ2yXVvRxiVFqIoMS kKcJiMV9t/O74Jp2YBOOHIh+t0KZM+LwWQhv2QotoJ5/g6yzHFqOuBqkBbX7Z6r393nV k58VADVv2V+MBSLkpW0acKXNXKYB3w2L9ZJM16Axi2XKRkjSPdK6iTiXPvWU57B7xjQP GRqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hw8-20020a170907a0c800b006fec2f4c252si11815731ejc.135.2022.05.30.01.44.31; Mon, 30 May 2022 01:44:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233134AbiE3IMf (ORCPT + 99 others); Mon, 30 May 2022 04:12:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233180AbiE3IMe (ORCPT ); Mon, 30 May 2022 04:12:34 -0400 Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D7E3437A33 for ; Mon, 30 May 2022 01:12:33 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-563-GjQ-5gtcOuOz68g1S0Fdlg-1; Mon, 30 May 2022 04:12:29 -0400 X-MC-Unique: GjQ-5gtcOuOz68g1S0Fdlg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 61651100BAA8; Mon, 30 May 2022 08:12:29 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.64.242.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C18B1410F36; Mon, 30 May 2022 08:12:26 +0000 (UTC) From: Gopal Tiwari To: linux-bluetooth@vger.kernel.org Cc: luiz.dentz@gmail.com, gtiwari@redhat.com Subject: [Bluez 04/13] Fixing memory leak in sixaxis.c Date: Mon, 30 May 2022 13:42:00 +0530 Message-Id: <20220530081209.560465-5-gopalkrishna.tiwari@gmail.com> In-Reply-To: <20220530081209.560465-1-gopalkrishna.tiwari@gmail.com> References: <20220530081209.560465-1-gopalkrishna.tiwari@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Gopal Tiwari While performing static tool analysis using coverity found following reports for resouse leak bluez-5.64/plugins/sixaxis.c:425: alloc_arg: "get_pairing_type_for_device" allocates memory that is stored into "sysfs_path". bluez-5.64/plugins/sixaxis.c:428: leaked_storage: Variable "sysfs_path" going out of scope leaks the storage it points to. Fixing them. Signed-off-by: Gopal Tiwari --- plugins/sixaxis.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/sixaxis.c b/plugins/sixaxis.c index ddecbcccb..9249c2715 100644 --- a/plugins/sixaxis.c +++ b/plugins/sixaxis.c @@ -424,10 +424,15 @@ static void device_added(struct udev_device *udevice) cp = get_pairing_type_for_device(udevice, &bus, &sysfs_path); if (!cp || (cp->type != CABLE_PAIRING_SIXAXIS && - cp->type != CABLE_PAIRING_DS4)) + cp->type != CABLE_PAIRING_DS4)) { + g_free(sys_path); return; - if (bus != BUS_USB) + } + + if (bus != BUS_USB) { + g_free(sys_path); return; + } info("sixaxis: compatible device connected: %s (%04X:%04X %s)", cp->name, cp->vid, cp->pid, sysfs_path); -- 2.26.2