Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp4373608ioo; Tue, 31 May 2022 03:02:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMQyRaj1oOoPnwp5EntDPP1p7GtSYFAHW3rjvZ4XBeUIjNrYR2+WtWssHVtTE2g3IA1xC4 X-Received: by 2002:a17:90a:1b84:b0:1e0:493a:425c with SMTP id w4-20020a17090a1b8400b001e0493a425cmr27729480pjc.200.1653991355343; Tue, 31 May 2022 03:02:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653991355; cv=none; d=google.com; s=arc-20160816; b=rSY27UTxNLe6Ls6iYiGptzeX4XRHgAvYOjF1k3DWsaq3J/6D5kCJR+6byDgIHNyzNx ueCvm3l8M3+40EWQf/NTJ3MjKG+XEyBUUQ7iLqS8fgxz4T91a4A6BEsMfkzUgFilXsu9 q5ikHLlSuJ4EJefLIJgAvd8GfRAgM9vg2fYvqT9Yxxhg4ZSVyISBR+5t/5Do41KVVbjF ljkgCwTh1zi5w1x0WJ6eCxSr/7petWvhHjrw8yWtlk8HZY+qQ3UxKFIWeXS+CgkGRDsr b92njSSgavPiQyc02aYCVjFf41moQJHvukGEuQrK1Vesdg3JTLIkwzYU4813b8al80DW MuuQ== 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=caUbLCeFpArcMPkPGsHCPiTCKjyb5zWGSr+ZegH5Iqs=; b=LRBQGAnQyVhaR1OmWL0Wzra51SwwMO4CZxKryfT/3TX5Eo8vHKja8a7bo4BidtObif EWi7/n3j59LM0jgA/tv1S0hpXUZuO0T5jnR6G2FazYzvjc7p8DRSM8RjjYCvYW+kIwkE 0xMwGxjECjUxvewEJSBeGXG0Po9i4uzHvXScilj//VO0IH67A5/duopTa+JyVmL3PqAh Vz3Zu1vy3guVhvJhma9iEZ+XMoBAv8EFxXq5T+CtteWhoWVF6ztj6RCZxniuHqxo6byN hGzgPYNp5YP+FqSsaDbWN3zUJwfHiaj+tXVawTthYuVyGPX180UUIJWV6RYiisEAlIIk 3ueQ== 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 z4-20020a17090a7b8400b001cb63b8d659si2167445pjc.60.2022.05.31.03.02.01; Tue, 31 May 2022 03:02:35 -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 S244560AbiEaHlg (ORCPT + 99 others); Tue, 31 May 2022 03:41:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244566AbiEaHlf (ORCPT ); Tue, 31 May 2022 03:41:35 -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 0C2408D68D for ; Tue, 31 May 2022 00:41: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-578-sIRHd_r7NjyK8nzKz0QJBw-1; Tue, 31 May 2022 03:41:31 -0400 X-MC-Unique: sIRHd_r7NjyK8nzKz0QJBw-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 35C2E85A5BC; Tue, 31 May 2022 07:41:31 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.64.242.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F68B140EBD5; Tue, 31 May 2022 07:41:28 +0000 (UTC) From: Gopal Tiwari To: linux-bluetooth@vger.kernel.org Cc: luiz.dentz@gmail.com, gtiwari@redhat.com Subject: [Bluez V2 02/13] Fixing memory leakage in appkey.c Date: Tue, 31 May 2022 13:11:06 +0530 Message-Id: <20220531074117.610321-3-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 the static analysis using the coverity tool found following memory leak reports bluez-5.64/mesh/appkey.c:143: leaked_storage: Variable "key" going out of scope leaks the storage it points to. Error: RESOURCE_LEAK (CWE-772): bluez-5.64/mesh/appkey.c:146: leaked_storage: Variable "key" going out of scope leaks the storage it points to. Fixing them. Signed-off-by: Gopal Tiwari --- mesh/appkey.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mesh/appkey.c b/mesh/appkey.c index 5088a1812..52fed8c31 100644 --- a/mesh/appkey.c +++ b/mesh/appkey.c @@ -139,11 +139,15 @@ bool appkey_key_init(struct mesh_net *net, uint16_t net_idx, uint16_t app_idx, key->net_idx = net_idx; key->app_idx = app_idx; - if (key_value && !set_key(key, app_idx, key_value, false)) + if (key_value && !set_key(key, app_idx, key_value, false)) { + appkey_key_free(key); return false; + } - if (new_key_value && !set_key(key, app_idx, new_key_value, true)) + if (new_key_value && !set_key(key, app_idx, new_key_value, true)) { + appkey_key_free(key); return false; + } l_queue_push_tail(app_keys, key); -- 2.26.2