Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5463529ioo; Wed, 1 Jun 2022 06:11:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzeDWj0DNRQ10VHX8ATk5XevUx5Z5LnMlNzybdyrG4NEArbw+qqHosHcPZO1L6dNFe8PNst X-Received: by 2002:a63:8642:0:b0:3fc:a5ee:678 with SMTP id x63-20020a638642000000b003fca5ee0678mr2445156pgd.178.1654089074402; Wed, 01 Jun 2022 06:11:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654089074; cv=none; d=google.com; s=arc-20160816; b=YXNMiBj9HV0YkvyqjviMnrNGJjeN0YF39pRMivJJlGZftzNurW0+x3ds72B+SoGVJf 1dGYclzIPJk8aELNq6Lrc4/ok87EWlWve2CghVdT41c2RGrlZMnTV0X4gHgcaX4JYNbY nhWI3hJBeM6A82uRWe3gVSiAk5YUhFg02vCFxeTnPuXV5zH4DmuR7hBIJ8HR1IAr04dN WBHhO8hpuW1WqBkPoSKJExOWBFZeaEZl6IIdJp+RmBrscV7oSfEiDFPD7cWVWObZYjpg xpvnCNwB5ewIEpV/Q3mAHpk87CsQOapT3ahT0RdQFGHpZKBoqNLtMGMeO/CNK8NMsdJS SdmA== 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=AMQdIktbpHXRlHL1pMzEfpVWoSCHYtSvftSPq8TdQBY=; b=rmPUPGtGO/LOscxGmHvKh9uaMdVVaxitVeHpcsOs12fsY+ah/GSiqdSaABSjVJkyK9 fvyw0as7fvN8foxELb9zRYWfZmOD/acTc6lboY4I3FdJ1n+Zg8RL8AaQCk6kB8kFrDN7 ud1jo87nDfku0ADzxGbS9/VEquyZ2TzXuYTa7EwXs5nObwvEVZOY0sXZ4LgHL11nHxDp Riu5CotwiCb2pMiLgVPq93itk+2ZwebS4e0bCMQgI6EEsKBgcs4WkrNsHyaZ5UIG6mNJ vDmIefXlSamiobEVKf8R6WUCkXS3A1fvP1idNNXJAmYZwvhEnpnx7fEX27AbAI+mvujb QVpA== 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 12-20020a63010c000000b003f5e7c0649bsi2335149pgb.698.2022.06.01.06.10.45; Wed, 01 Jun 2022 06:11:14 -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 S244562AbiEaHlm (ORCPT + 99 others); Tue, 31 May 2022 03:41:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244565AbiEaHll (ORCPT ); Tue, 31 May 2022 03:41:41 -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 A89C025D3 for ; Tue, 31 May 2022 00:41:40 -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-179-ifshmUf9PeitAYIII_8KzQ-1; Tue, 31 May 2022 03:41:37 -0400 X-MC-Unique: ifshmUf9PeitAYIII_8KzQ-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 660F1185A79C; Tue, 31 May 2022 07:41:37 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.64.242.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D698140EBD5; Tue, 31 May 2022 07:41:34 +0000 (UTC) From: Gopal Tiwari To: linux-bluetooth@vger.kernel.org Cc: luiz.dentz@gmail.com, gtiwari@redhat.com Subject: [Bluez V2 04/13] Fixing memory leak in sixaxis.c Date: Tue, 31 May 2022 13:11:08 +0530 Message-Id: <20220531074117.610321-5-gopalkrishna.tiwari@gmail.com> In-Reply-To: <20220531074117.610321-1-gopalkrishna.tiwari@gmail.com> References: <20220531074117.610321-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..10cf15948 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(sysfs_path); return; - if (bus != BUS_USB) + } + + if (bus != BUS_USB) { + g_free(sysfs_path); return; + } info("sixaxis: compatible device connected: %s (%04X:%04X %s)", cp->name, cp->vid, cp->pid, sysfs_path); -- 2.26.2