Received: by 2002:a19:771d:0:0:0:0:0 with SMTP id s29csp1266013lfc; Wed, 1 Jun 2022 13:34:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9JzpthLoJttgmNqpAmNhktLuedchrn9RvZ9ZvkWEu/nn7asfGKOKeL15/2YPuUx3CC8ic X-Received: by 2002:a17:902:e845:b0:163:ebca:a026 with SMTP id t5-20020a170902e84500b00163ebcaa026mr1269345plg.40.1654115678349; Wed, 01 Jun 2022 13:34:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654115678; cv=none; d=google.com; s=arc-20160816; b=0wFOtoUTN0cWyFmxjMLooeGUgN4WDLw7zqr3rK1og1M3U/FKA12QjxdYjEsiWvS5ZQ yrdK2NlRWXilN6+yENT8w2qL8X+ULWszlHpUUmO0Szy1vWXPs7sXm9QrANgNCnPMjKZO +dBBLdDk/PB+P89xMk3eP/C/5WHI4tAJ2PKMp/WN97rgLtjfWCVkLF17M2Wz8s0FdsMT mrB1i9c9eHXJ1JTDdt2p8/Lm5jOmhlD54vm09xYLo0mtl1B2dX/ic3aiLQbTWhQpxniF C7lQLQ73gWdPboIW9HgiNO4YJVUbWFFxtgGt2PKUb8F9IMBTClA9aHEuGvCZqULRUtYN B+5g== 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=2Ky2QC3N9TT+53gkDI8Yr4PHwpg3UWYFIFln9k2W2mE=; b=PWxW5GZNQ4IzUfPa95t14A8U1Y9HRWrVlFlzpoFhU28H3XJRKo+tjQfLMz/TsTPTih 0g1JMZbwpwa+itvAjPajRd6HRxh4qylkodzkL1OeczEcvBexu1m3CO+qct+lZiiePvEH W81lI/HdLbNvL+ioHtB8RmRRCFzIrgrvJIn/bcgscu6K0cHcRt0fUebumDKl+TULu1Gc 04IQ88ZURnn3Phg92Zwsc2RVTMLLgDtNjgbZU4g2r+j1TOMeOBuuf4/27BqzrXr2Sj8R JrIR8SZ7mQmyzWTsRvxVRN5pyxGZyayR4lm7SyZVYoH62/GyYaar9ZzVZvSb9gaXjNIs ROug== 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:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id w62-20020a638241000000b003fc6a2458b4si3427297pgd.770.2022.06.01.13.34.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 13:34:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4048F27E464; Wed, 1 Jun 2022 12:44:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244564AbiEaHlf (ORCPT + 99 others); Tue, 31 May 2022 03:41:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244561AbiEaHlc (ORCPT ); Tue, 31 May 2022 03:41:32 -0400 Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8C65E8CCEE for ; Tue, 31 May 2022 00:41:30 -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-558-6BGb8hCeOUCnD5ofEBvGWA-1; Tue, 31 May 2022 03:41:28 -0400 X-MC-Unique: 6BGb8hCeOUCnD5ofEBvGWA-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 E4DB085A5B9; Tue, 31 May 2022 07:41:27 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.64.242.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77CFC1410DDB; Tue, 31 May 2022 07:41:25 +0000 (UTC) From: Gopal Tiwari To: linux-bluetooth@vger.kernel.org Cc: luiz.dentz@gmail.com, gtiwari@redhat.com Subject: [Bluez V2 01/13] Fixing memory leak issue in gatt.c Date: Tue, 31 May 2022 13:11:05 +0530 Message-Id: <20220531074117.610321-2-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.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,SPOOFED_FREEMAIL_NO_RDNS,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 the static tool analysis using coverity tool found following reports Error: RESOURCE_LEAK (CWE-772): bluez-5.64/client/gatt.c:1531: leaked_storage: Variable "service" going out of scope leaks the storage it points to. Error: RESOURCE_LEAK (CWE-772): bluez-5.64/client/gatt.c:2626: leaked_storage: Variable "chrc" going out of scope leaks the storage it points to. Error: RESOURCE_LEAK (CWE-772): bluez-5.64/client/gatt.c:2906: leaked_storage: Variable "desc" going out of scope leaks the storage it points to. Fixing them. Signed-off-by: Gopal Tiwari --- client/gatt.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/client/gatt.c b/client/gatt.c index 13872c794..4c1efaf75 100644 --- a/client/gatt.c +++ b/client/gatt.c @@ -1527,8 +1527,10 @@ void gatt_register_service(DBusConnection *conn, GDBusProxy *proxy, if (argc > 2) { service->handle = parse_handle(argv[2]); - if (!service->handle) + if (!service->handle) { + service_free(service); return bt_shell_noninteractive_quit(EXIT_FAILURE); + } } if (g_dbus_register_interface(conn, service->path, @@ -2622,8 +2624,10 @@ void gatt_register_chrc(DBusConnection *conn, GDBusProxy *proxy, if (argc > 3) { chrc->handle = parse_handle(argv[3]); - if (!chrc->handle) + if (!chrc->handle) { + chrc_free(chrc); return bt_shell_noninteractive_quit(EXIT_FAILURE); + } } if (g_dbus_register_interface(conn, chrc->path, CHRC_INTERFACE, @@ -2902,8 +2906,10 @@ void gatt_register_desc(DBusConnection *conn, GDBusProxy *proxy, if (argc > 3) { desc->handle = parse_handle(argv[3]); - if (!desc->handle) + if (!desc->handle) { + desc_free(desc); return bt_shell_noninteractive_quit(EXIT_FAILURE); + } } if (g_dbus_register_interface(conn, desc->path, DESC_INTERFACE, -- 2.26.2