Skip to contentSkip to conversation

audio: Fix memory leak of AVDTP buffer

PATCH In review Luiz Augusto von Dentz 2 participants 3 messages Oct 9, 2012 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/2 audio: Fix memory leak of AVDTP buffer

From: Luiz Augusto von Dentz <[email protected]>

Upon disconnection all references to AVDTP session should be release otherwise the data associate with it cannot be freed and new connection may overwrite the buf pointer causing it to leak.

---
 audio/sink.c   | 8 ++++++++
 audio/source.c | 8 ++++++++
 2 files changed, 16 insertions(+)
audio/sink.c +8 -0
index 4eb2c61..0628fd2 100644
@@ -125,6 +125,14 @@ static void sink_set_state(struct audio_device *dev, sink_state_t new_state)
 		struct sink_state_callback *cb = l->data;
 		cb->cb(dev, old_state, new_state, cb->user_data);
 	}
+
+	if (new_state != SINK_STATE_DISCONNECTED)
+		return;
+
+	if (sink->session) {
+		avdtp_unref(sink->session);
+		sink->session = NULL;
+	}
 }
 
 static void avdtp_state_callback(struct audio_device *dev,
audio/source.c +8 -0
index 41aedd2..e111954 100644
@@ -116,6 +116,14 @@ static void source_set_state(struct audio_device *dev, source_state_t new_state)
 		struct source_state_callback *cb = l->data;
 		cb->cb(dev, old_state, new_state, cb->user_data);
 	}
+
+	if (new_state != SOURCE_STATE_DISCONNECTED)
+		return;
+
+	if (source->session) {
+		avdtp_unref(source->session);
+		source->session = NULL;
+	}
 }
 
 static void avdtp_state_callback(struct audio_device *dev,
Signature · 1 line
1.7.11.4
author maintainer
#1 lore raw

PATCH 2/2 sink: Remove deprecated code

From: Luiz Augusto von Dentz <[email protected]>

Remove decrecated properties and signals

---
 audio/sink.c      | 52 ----------------------------------------------------
 doc/audio-api.txt | 29 +----------------------------
 2 files changed, 1 insertion(+), 80 deletions(-)
audio/sink.c +0 -52
index 0628fd2..d45185c 100644
@@ -148,15 +148,6 @@ static void avdtp_state_callback(struct audio_device *dev,
 
 	switch (new_state) {
 	case AVDTP_SESSION_STATE_DISCONNECTED:
-		if (sink->state != SINK_STATE_CONNECTING) {
-			gboolean value = FALSE;
-			g_dbus_emit_signal(btd_get_dbus_connection(), dev->path,
-					AUDIO_SINK_INTERFACE, "Disconnected",
-					DBUS_TYPE_INVALID);
-			emit_property_changed(dev->path,
-					AUDIO_SINK_INTERFACE, "Connected",
-					DBUS_TYPE_BOOLEAN, &value);
-		}
 		sink_set_state(dev, SINK_STATE_DISCONNECTED);
 		break;
 	case AVDTP_SESSION_STATE_CONNECTING:
@@ -189,7 +180,6 @@ static void stream_state_changed(struct avdtp_stream *stream,
 	DBusConnection *conn = btd_get_dbus_connection();
 	struct audio_device *dev = user_data;
 	struct sink *sink = dev->sink;
-	gboolean value;
 
 	if (err)
 		return;
@@ -216,38 +206,9 @@ static void stream_state_changed(struct avdtp_stream *stream,
 		sink->cb_id = 0;
 		break;
 	case AVDTP_STATE_OPEN:
-		if (old_state == AVDTP_STATE_CONFIGURED &&
-				sink->state == SINK_STATE_CONNECTING) {
-			value = TRUE;
-			g_dbus_emit_signal(conn, dev->path,
-						AUDIO_SINK_INTERFACE,
-						"Connected",
-						DBUS_TYPE_INVALID);
-			emit_property_changed(dev->path,
-						AUDIO_SINK_INTERFACE,
-						"Connected",
-						DBUS_TYPE_BOOLEAN, &value);
-		} else if (old_state == AVDTP_STATE_STREAMING) {
-			value = FALSE;
-			g_dbus_emit_signal(conn, dev->path,
-						AUDIO_SINK_INTERFACE,
-						"Stopped",
-						DBUS_TYPE_INVALID);
-			emit_property_changed(dev->path,
-						AUDIO_SINK_INTERFACE,
-						"Playing",
-						DBUS_TYPE_BOOLEAN, &value);
-		}
 		sink_set_state(dev, SINK_STATE_CONNECTED);
 		break;
 	case AVDTP_STATE_STREAMING:
-		value = TRUE;
-		g_dbus_emit_signal(conn, dev->path,
-					AUDIO_SINK_INTERFACE, "Playing",
-					DBUS_TYPE_INVALID);
-		emit_property_changed(dev->path,
-					AUDIO_SINK_INTERFACE, "Playing",
-					DBUS_TYPE_BOOLEAN, &value);
 		sink_set_state(dev, SINK_STATE_PLAYING);
 		break;
 	case AVDTP_STATE_CONFIGURED:
@@ -505,7 +466,6 @@ static DBusMessage *sink_get_properties(DBusConnection *conn,
 	DBusMessageIter iter;
 	DBusMessageIter dict;
 	const char *state;
-	gboolean value;
 
 	reply = dbus_message_new_method_return(msg);
 	if (!reply)
@@ -518,14 +478,6 @@ static DBusMessage *sink_get_properties(DBusConnection *conn,
 			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
 			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
 
-	/* Playing */
-	value = (sink->stream_state == AVDTP_STATE_STREAMING);
-	dict_append_entry(&dict, "Playing", DBUS_TYPE_BOOLEAN, &value);
-
-	/* Connected */
-	value = (sink->stream_state >= AVDTP_STATE_CONFIGURED);
-	dict_append_entry(&dict, "Connected", DBUS_TYPE_BOOLEAN, &value);
-
 	/* State */
 	state = state2str(sink->state);
 	if (state)
@@ -546,10 +498,6 @@ static const GDBusMethodTable sink_methods[] = {
 };
 
 static const GDBusSignalTable sink_signals[] = {
-	{ GDBUS_DEPRECATED_SIGNAL("Connected", NULL) },
-	{ GDBUS_DEPRECATED_SIGNAL("Disconnected", NULL) },
-	{ GDBUS_DEPRECATED_SIGNAL("Playing", NULL) },
-	{ GDBUS_DEPRECATED_SIGNAL("Stopped", NULL) },
 	{ GDBUS_SIGNAL("PropertyChanged",
 			GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
 	{ }
doc/audio-api.txt +1 -28
index ca430fc..72129fc 100644
@@ -200,24 +200,7 @@ Methods		void Connect()
 
 			Possible Errors: org.bluez.Error.InvalidArguments
 
-Signals		void Connected() {deprecated}
-
-			Sent when a successful connection has been made to the
-			remote A2DP Sink
-
-		void Disconnected() {deprecated}
-
-			Sent when the device has been disconnected from.
-
-		void Playing() {deprecated}
-
-			Sent when a stream with remote device is started.
-
-		void Stopped() {deprecated}
-
-			Sent when a stream with remote device is suspended.
-
-		PropertyChanged(string name, variant value)
+Signals		PropertyChanged(string name, variant value)
 
 			This signal indicates a changed value of the given
 			property.
@@ -247,16 +230,6 @@ properties	string State [readonly]
 			"playing" -> "disconnected"
 				Disconnected from the remote device
 
-		boolean Connected [readonly]
-
-			Indicates if a stream is setup to a A2DP sink on
-			the remote device.
-
-		boolean Playing  [readonly]
-
-			Indicates if a stream is active to a A2DP sink on
-			the remote device.
-
 AudioSource hierarchy
 =====================
 
Signature · 1 line
1.7.11.4
#2 lore raw
In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 7 lines · Luiz Augusto von Dentz

Upon disconnection all references to AVDTP session should be release otherwise the data associate with it cannot be freed and new connection may overwrite the buf pointer causing it to leak.

---
 audio/sink.c   | 8 ++++++++
 audio/source.c | 8 ++++++++
 2 files changed, 16 insertions(+)

Both patches have been applied. Thanks.

Johan