Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp4506115ioo; Tue, 31 May 2022 06:05:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyE0nHIPPuuXKS02k/0GdJWibGWJAzT6V8NWAIUDZuIxaK81Kli1HuKc4Xv66MQOnUdv+oh X-Received: by 2002:a17:90a:4896:b0:1de:fff2:6c48 with SMTP id b22-20020a17090a489600b001defff26c48mr28880290pjh.89.1654002311650; Tue, 31 May 2022 06:05:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654002311; cv=none; d=google.com; s=arc-20160816; b=Db8enZJ/3CQ7O0mU/iTh0KMU9JX5s6FxZN5l3neaKs/rEYUIYilX/GsNNWsUIt9XEJ sxE8cwKMLTPs0X3Iy0lio6mv1pCv1IWf1LTDimBDtgqYoS4BbR42vmIBLGySOBRGb+Nk MO72KRz4DysykqAJnMiZFYxzNh6JO2LxwT/YPhn1KZCjQyB2Q/Bp37fzy+FtkzE+5+lX 8hngbYxrP38w5dZNCYN8BsyWFRboRpbA0sqp2wmYdQFyfCjbRKUWzUAH1briwr3czRq9 XUpCcVHkZE1hfmyUlh9H7jzlKcTCZGvOHpNuM4Mq1sJIlLU6ed3yZK8YBAaxRAxw7361 Ehxg== 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=+PBflrsy7AHSK0/fJNfGiB/vWZZc/EbIGuxnw+h+QeA=; b=mHdgtycPw6O2WU7lRHwKyj9SIfrOu7UhnuySThwyJE7Na1dvQjslC+ptfne+iqFoJm m6AurqV/qsDr3/A9msNlQ48PkQpeZJl5ff7t6G7+LjoJwPaXdGVatugbGnr8wr5iVlSZ rixLAGc6WcroImBhjVSpF55pPu3LFH/nGNrqDWyubBab/o/pID4Zug6V3LmklXcx7Vcg ltkgPtKqQpRQ9L3zvW6Bbj5AsFRjar9bGZpDW4HRLaX/fkokwFivjyHcUdCGjnZnxcE6 2YLHTkTmfv8ygTCPJnhcD6HluB8hWtXf7YTsM6/bxj9Z9SJqW1PTVPSYfvh31g9wtHfz RPBg== 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 bf4-20020a170902b90400b0015ce8cd506asi18124276plb.325.2022.05.31.06.04.40; Tue, 31 May 2022 06:05:11 -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 S244584AbiEaHmO (ORCPT + 99 others); Tue, 31 May 2022 03:42:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244574AbiEaHmC (ORCPT ); Tue, 31 May 2022 03:42:02 -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 B22431583F for ; Tue, 31 May 2022 00:41:45 -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-516-UNdZwoqWMdi7UZXAgr4LGg-1; Tue, 31 May 2022 03:41:43 -0400 X-MC-Unique: UNdZwoqWMdi7UZXAgr4LGg-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 6B8993810D44; Tue, 31 May 2022 07:41:43 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.64.242.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id 446961410DDB; Tue, 31 May 2022 07:41:40 +0000 (UTC) From: Gopal Tiwari To: linux-bluetooth@vger.kernel.org Cc: luiz.dentz@gmail.com, gtiwari@redhat.com Subject: [Bluez V2 06/13] Fixing leaked_handle in create-image.c Date: Tue, 31 May 2022 13:11:10 +0530 Message-Id: <20220531074117.610321-7-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/tools/create-image.c:124: leaked_storage: Variable "map" going out of scope leaks the storage it points to. Signed-off-by: Gopal Tiwari --- tools/create-image.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/create-image.c b/tools/create-image.c index aba940da7..90cd87315 100644 --- a/tools/create-image.c +++ b/tools/create-image.c @@ -97,12 +97,13 @@ static void write_block(FILE *fp, const char *pathname, unsigned int ino, map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); if (!map || map == MAP_FAILED) { - close(fd); - fd = -1; map = NULL; st.st_size = 0; } + close(fd); + fd = -1; + done: fprintf(fp, HDR_FMT, HDR_MAGIC, ino, mode, 0, 0, 1, 0, (uintmax_t) st.st_size, 0, 0, 0, 0, namelen + 1, 0, name); @@ -117,9 +118,7 @@ done: pad = 3 - ((st.st_size + 3) % 4); for (i = 0; i < pad; i++) fputc(0, fp); - munmap(map, st.st_size); - close(fd); } } -- 2.26.2