Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp3435073ioo; Mon, 30 May 2022 01:55:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMM2ixHCqrocsDXkDmCf+07Qr3duzS/cVFQ1vopdXiRqpBweUMxm85Pmlz3gfHuQ9ni0rg X-Received: by 2002:a05:6402:1e95:b0:42a:c466:52ad with SMTP id f21-20020a0564021e9500b0042ac46652admr57880297edf.340.1653900920093; Mon, 30 May 2022 01:55:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653900920; cv=none; d=google.com; s=arc-20160816; b=Tq/2UELLsXWqZfC6Btao9JqqUOn5t1h3TSfuYHiRWbDVZF576sP+UPZAMiqLfKAWxi iRWXH0jdJYqgiG69L/Xd5SEWbl7vf7vrzv19Zp3JpEAfeFMiS2pW1lN+Xm6gKBXFZ4ef JTeA9gTb441LPg0Rz9Y2mrbWsWib90cucfn/5LIPG1IpoeOFuiDvqOMzDLD3uNkqKlWS yCJ23mllqsG49Q6dLd9T5l5AdUpOq/knnJynZPVyJerWje6t18rsai2KjUsEEsmEPkrc AefQugOqdTnBrojG+yHkuqY3lbi0jKFLrbtC2quF9zuftZxEHYtXNXTfaPCGrfutkw0e q5Jg== 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=ZqvpYurk0QpM57z8AtjdRg4b3UNZJ2XQ7VKzbZGo4WQ=; b=SHhW/A3cW6lk9pjoaU6zBmYqFEM7HDr1PBOeSJBLfvcSnIhZNVtojaNMlIILR7ZMx3 lYo8KDMq70F/hurAGew+cxhsL1EhYTY8ag+bnYHo15fRIO5CGsb+NsVdUwZi2UDT3dN/ Kagt+jHj8X9UJnpykW9V5lug7jcFnISime+1D/IOXgF24zNmbhZ36k+uVwTGzUy1uk81 ErDaeKQhfhD4vdQiSeW33H6S+EcFiELqC+6ce3iyc5yUUfZtWzEWLwxvoGBEK4DNw0rU cNVrlxyYTn9FdYs7IcZsvTPE4C79JNTYlPk4SuY39c37AiocgrrLOHhY6B4unTDmJv8k YNJg== 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 gb11-20020a170907960b00b006e8c1be7b7asi6249287ejc.274.2022.05.30.01.54.54; Mon, 30 May 2022 01:55:20 -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 S233205AbiE3IM5 (ORCPT + 99 others); Mon, 30 May 2022 04:12:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233318AbiE3IMs (ORCPT ); Mon, 30 May 2022 04:12:48 -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 520A76E8D2 for ; Mon, 30 May 2022 01:12:45 -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-372-aO-wbx35PFy0OyHpE-IJbQ-1; Mon, 30 May 2022 04:12:36 -0400 X-MC-Unique: aO-wbx35PFy0OyHpE-IJbQ-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 CAA2880A0B9; Mon, 30 May 2022 08:12:35 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.64.242.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2B57140EBD5; Mon, 30 May 2022 08:12:33 +0000 (UTC) From: Gopal Tiwari To: linux-bluetooth@vger.kernel.org Cc: luiz.dentz@gmail.com, gtiwari@redhat.com Subject: [Bluez 06/13] Fixing leaked_handle in create-image.c Date: Mon, 30 May 2022 13:42:02 +0530 Message-Id: <20220530081209.560465-7-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 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