diff mbox series

[BlueZ,2/2] shared/bap: Set stream lpac to NULL after removing the stream.

Message ID 20230927062436.6306-3-andrei.istodorescu@nxp.com
State New
Headers show
Series Memory leaks and memory used after free fixes | expand

Commit Message

Andrei Istodorescu Sept. 27, 2023, 6:24 a.m. UTC
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(-)

--
2.39.2
diff mbox series

Patch

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)