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 (mailing list archive)
State New, archived
Headers show
Series Memory leaks and memory used after free fixes | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch warning WARNING:LONG_LINE_COMMENT: line length of 111 exceeds 80 columns #119: FILE: src/shared/bap.c:2685: + stream->lpac = NULL; /* mark stream->lpac to NULL, as it will be freed in bt_bap_remove_pac */ /github/workspace/src/src/13400000.patch total: 0 errors, 1 warnings, 11 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /github/workspace/src/src/13400000.patch has style problems, please review. NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS.
tedd_an/GitLint fail WARNING: I3 - ignore-body-lines: gitlint will be switching from using Python regex 'match' (match beginning) to 'search' (match anywhere) semantics. Please review your ignore-body-lines.regex option accordingly. To remove this warning, set general.regex-style-search=True. More details: https://jorisroovers.github.io/gitlint/configuration/#regex-style-search 1: T3 Title has trailing punctuation (.): "[BlueZ,2/2] shared/bap: Set stream lpac to NULL after removing the stream."
tedd_an/IncrementalBuild success Incremental Build PASS

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)