diff mbox series

[Bluez,v1,2/3] audio: unref session when failed to setup

Message ID 20201104133318.Bluez.v1.2.I4c872b9b8fdee53a335db41acbb6e59fe9692cc5@changeid (mailing list archive)
State Superseded
Headers show
Series [Bluez,v1,1/3] policy: add checks before connecting | expand

Commit Message

Archie Pusaka Nov. 4, 2020, 5:35 a.m. UTC
From: Archie Pusaka <apusaka@chromium.org>

There is a possibility to miss unref-ing when source/sink fails at
setup.

Reviewed-by: Sonny Sasaka <sonnysasaka@chromium.org>
---

 profiles/audio/sink.c   | 5 ++++-
 profiles/audio/source.c | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/profiles/audio/sink.c b/profiles/audio/sink.c
index 134d157bc6..d672670e25 100644
--- a/profiles/audio/sink.c
+++ b/profiles/audio/sink.c
@@ -258,8 +258,11 @@  gboolean sink_setup_stream(struct btd_service *service, struct avdtp *session)
 
 	sink->connect_id = a2dp_discover(sink->session, discovery_complete,
 								sink);
-	if (sink->connect_id == 0)
+	if (sink->connect_id == 0) {
+		avdtp_unref(sink->session);
+		sink->session = NULL;
 		return FALSE;
+	}
 
 	return TRUE;
 }
diff --git a/profiles/audio/source.c b/profiles/audio/source.c
index fca85d4cb3..c706c928a7 100644
--- a/profiles/audio/source.c
+++ b/profiles/audio/source.c
@@ -259,8 +259,11 @@  gboolean source_setup_stream(struct btd_service *service,
 
 	source->connect_id = a2dp_discover(source->session, discovery_complete,
 								source);
-	if (source->connect_id == 0)
+	if (source->connect_id == 0) {
+		avdtp_unref(source->session);
+		source->session = NULL;
 		return FALSE;
+	}
 
 	return TRUE;
 }