linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrei Istodorescu <andrei.istodorescu@nxp.com>
To: linux-bluetooth@vger.kernel.org
Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com,
	silviu.barbulescu@nxp.com, vlad.pruteanu@nxp.com,
	iulia.tanasescu@nxp.com, luiz.dentz@gmail.com,
	Andrei Istodorescu <andrei.istodorescu@nxp.com>
Subject: [PATCH BlueZ 2/2] shared/bap: Set stream lpac to NULL after removing the stream.
Date: Wed, 27 Sep 2023 09:24:36 +0300	[thread overview]
Message-ID: <20230927062436.6306-3-andrei.istodorescu@nxp.com> (raw)
In-Reply-To: <20230927062436.6306-1-andrei.istodorescu@nxp.com>

This is required as the pac is freed in another place and will result
in a dangling pointer.
---
 src/shared/bap.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/shared/bap.c b/src/shared/bap.c
index 1c43680c2457..a0f0135eb135 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -2681,8 +2681,10 @@ static void remove_streams(void *data, void *user_data)
 	struct bt_bap_stream *stream;

 	stream = queue_remove_if(bap->streams, match_stream_lpac, pac);
-	if (stream)
+	if (stream) {
+		stream->lpac = NULL; /* mark stream->lpac to NULL, as it will be freed in bt_bap_remove_pac  */
 		bt_bap_stream_release(stream, NULL, NULL);
+	}
 }

 bool bt_bap_remove_pac(struct bt_bap_pac *pac)
--
2.39.2


      parent reply	other threads:[~2023-09-27  6:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-27  6:24 [PATCH BlueZ 0/2] Memory leaks and memory used after free fixes Andrei Istodorescu
2023-09-27  6:24 ` [PATCH BlueZ 1/2] bap: Remove memory leaks and buffer usage after free Andrei Istodorescu
2023-09-27  8:02   ` Memory leaks and memory used after free fixes bluez.test.bot
2023-09-27 21:55   ` [PATCH BlueZ 1/2] bap: Remove memory leaks and buffer usage after free Luiz Augusto von Dentz
2023-09-27  6:24 ` Andrei Istodorescu [this message]

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=20230927062436.6306-3-andrei.istodorescu@nxp.com \
    --to=andrei.istodorescu@nxp.com \
    --cc=claudia.rosu@nxp.com \
    --cc=iulia.tanasescu@nxp.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=mihai-octavian.urzica@nxp.com \
    --cc=silviu.barbulescu@nxp.com \
    --cc=vlad.pruteanu@nxp.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).