Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3642332ioo; Mon, 30 May 2022 06:39:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1gPYzBtx5LnSjb9MfYNzVhBIadlPUdKFF9Hy/Dut92e87Iy35LU0268SVcaB9JAK+zxRf X-Received: by 2002:a17:906:58cb:b0:6ff:5282:dd83 with SMTP id e11-20020a17090658cb00b006ff5282dd83mr8131515ejs.510.1653917964562; Mon, 30 May 2022 06:39:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653917964; cv=none; d=google.com; s=arc-20160816; b=R5vb2CO8AwhNHVjKxNRhzFjaxaCIJg9g+KYkUcK0lUTxLkso1phLh2geDqe1ZumcAJ 3WkPWuPQMqjpTTliaKP95rsKXhxUV+7VFXJQPcAIOGHvQICfpvzmBlME4af3O/riWbpe oJaDiHUFnWT7zux6lXOE7AZgE1uBprFyHKPuP+KhQEcCHe7BUgTZECwrMrUa3T2KoRSX gsFPSPoo0SrejegGxlpY1RQrg9g0WxjhdQ1hoUJhfUpZLwcYSSbXuDdjWmDS7szjWjUI 48HZht/wJ7WZBGUvjpdbQq31FoT4DbT4KyPeXEbCyrY+eZ/kx+ot2ZxCsL/aqIyBj23c IqBA== 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=djqlRFEAVndXZP+mOEk3VUkJWYLb6h9pBH/9kVdoZfg=; b=t0QJw4/n/vKaQnfqX2T1ZO/4ZQHqd48mv2IhhKt0d+17GVtcOi1wWKw+98JVV00Vk2 mxPmeqF/dNxBm1opGHigVs345e6weSFU+OkYpFWxYMb+sWTzUMs4AaCPvUtvU+jpuEAI tvayxocK7tmOAjcvfkHut2VEvSrS5R83yfrBgi2e+k/4Tvh7RjTbz4vRlWHESJ3Cf25e LhWDEtk+ohCSP520GBbtqwOy6AhHhpsddbgxVTj3BsG7Hz+N56r2kAVGbijgUGURRaE3 KHm7Es6cNa7r3m+V5+Ts/H+LkgKQewhJACX6y8Ia27efLmMygkTgXuEfGX9mcDQRY/vR V4Ag== 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 l6-20020a056402254600b0042ad145b87fsi13987370edb.305.2022.05.30.06.38.51; Mon, 30 May 2022 06:39:24 -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 S232777AbiE3IM1 (ORCPT + 99 others); Mon, 30 May 2022 04:12:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233179AbiE3IMZ (ORCPT ); Mon, 30 May 2022 04:12:25 -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 D6BA41582F for ; Mon, 30 May 2022 01:12:24 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-635-vZzEjdVUOzqZgoRagGOx1A-1; Mon, 30 May 2022 04:12:19 -0400 X-MC-Unique: vZzEjdVUOzqZgoRagGOx1A-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 6D11429ABA2A; Mon, 30 May 2022 08:12:19 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.64.242.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id D5CB31410F36; Mon, 30 May 2022 08:12:16 +0000 (UTC) From: Gopal Tiwari To: linux-bluetooth@vger.kernel.org Cc: luiz.dentz@gmail.com, gtiwari@redhat.com Subject: [Bluez 01/13] Fixing memory leak issue in gatt.c Date: Mon, 30 May 2022 13:41:57 +0530 Message-Id: <20220530081209.560465-2-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 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 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/client/gatt.c b/client/gatt.c index 13872c794..100a4eb90 100644 --- a/client/gatt.c +++ b/client/gatt.c @@ -1527,7 +1527,8 @@ 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); } @@ -2622,8 +2623,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 +2905,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