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 01/13] Fixing memory leak issue in gatt.c
Date: Mon, 30 May 2022 13:41:57 +0530	[thread overview]
Message-ID: <20220530081209.560465-2-gopalkrishna.tiwari@gmail.com> (raw)
In-Reply-To: <20220530081209.560465-1-gopalkrishna.tiwari@gmail.com>

From: Gopal Tiwari <gtiwari@redhat.com>

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


  reply	other threads:[~2022-05-30  8:12 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 ` Gopal Tiwari [this message]
2022-05-30  8:40   ` 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 ` [Bluez 06/13] Fixing leaked_handle in create-image.c Gopal Tiwari
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-2-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.