All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gopal Tiwari <gopalkrishna.tiwari@gmail.com>
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	[thread overview]
Message-ID: <20220530081209.560465-7-gopalkrishna.tiwari@gmail.com> (raw)
In-Reply-To: <20220530081209.560465-1-gopalkrishna.tiwari@gmail.com>

From: Gopal Tiwari <gtiwari@redhat.com>

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 <gtiwari@redhat.com>
---
 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


  parent reply	other threads:[~2022-05-30  8:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-30  8:11 [Bluez 00/13] Fixing memory leak, leaked_handle and use_after Gopal Tiwari
2022-05-30  8:11 ` [Bluez 01/13] Fixing memory leak issue in gatt.c Gopal Tiwari
2022-05-30  8:40   ` Fixing memory leak, leaked_handle and use_after bluez.test.bot
2022-05-30  8:11 ` [Bluez 02/13] Fixing memory leakage in appkey.c Gopal Tiwari
2022-05-30  8:11 ` [Bluez 03/13] Fixing memroy leak in jlink.c Gopal Tiwari
2022-05-30  8:12 ` [Bluez 04/13] Fixing memory leak in sixaxis.c Gopal Tiwari
2022-05-30  8:12 ` [Bluez 05/13] Fixing leaked_handle in cltest.c Gopal Tiwari
2022-05-30  8:12 ` Gopal Tiwari [this message]
2022-05-30  8:12 ` [Bluez 07/13] Fixing leaked_handle in l2cap-tester.c Gopal Tiwari
2022-05-30  8:12 ` [Bluez 08/13] Fixing resource leak in mesh/mesh-db.c Gopal Tiwari
2022-05-30  8:12 ` [Bluez 09/13] Fixing leaked_handle in obex-client-tool.c Gopal Tiwari
2022-05-30  8:12 ` [Bluez 10/13] Fixing use after free in src/device.c Gopal Tiwari
2022-05-30  8:12 ` [Bluez 11/13] Fixing memory leak in pbap.c Gopal Tiwari
2022-05-30  8:12 ` [Bluez 12/13] Fixing possible use_after_free in meshctl.c Gopal Tiwari
2022-05-30  8:12 ` [Bluez 13/13] Fixing use_after_free in prov-db.c Gopal Tiwari

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220530081209.560465-7-gopalkrishna.tiwari@gmail.com \
    --to=gopalkrishna.tiwari@gmail.com \
    --cc=gtiwari@redhat.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.