Skip to contentSkip to conversation

audio: fix memory leak with typefinding

PATCH Superseded [email protected] 2 participants 4 messages Jun 23, 2010 – Jun 24, 2010 Bluetooth drivers

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 audio: fix memory leak with typefinding

From: Harri Mahonen <[email protected]>

sbc structure gets leaked each time when there is no data or SBC syncword, because sbc_finalize is not called. Call sbc_init after checking the data for syncword.

---
 audio/gstbluetooth.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
audio/gstbluetooth.c +2 -2
index 26dd4a5..11aefd7 100644
@@ -50,10 +50,10 @@ static void sbc_typefind(GstTypeFind *tf, gpointer ignore)
 	sbc_t sbc;
 	guint8 *data = gst_type_find_peek(tf, 0, 32);
 
-	if (sbc_init(&sbc, 0) < 0)
+	if (data == NULL || *data != 0x9c)	/* SBC syncword */
 		return;
 
-	if (data == NULL || *data != 0x9c)	/* SBC syncword */
+	if (sbc_init(&sbc, 0) < 0)
 		return;
 
 	aux = g_new(guint8, 32);
Signature · 1 line
1.7.0.4
#1 lore raw

Hi,

Quoted 18 lines · On Wed, Jun 23, 2010 at 10:10 PM, <[email protected]> wrote:

From: Harri Mahonen <[email protected]>

sbc structure gets leaked each time when there is no data or SBC syncword, because sbc_finalize is not called. Call sbc_init after checking the data for syncword.

---
 audio/gstbluetooth.c |    4 ++--

 1 files changed, 2 insertions(+), 2 deletions(-)
audio/gstbluetooth.c +0 -0
index 26dd4a5..11aefd7 100644
@@ -50,10 +50,10 @@ static void sbc_typefind(GstTypeFind *tf, gpointer ignore)
        sbc_t sbc;
        guint8 *data = gst_type_find_peek(tf, 0, 32);

audio/gstbluetooth.c static void sbc_typefind(GstTypeFind *tf, gpointer ignore) · line 59

Quoted 10 lines
audio/gstbluetooth.c +2 -2
 
-       if (sbc_init(&sbc, 0) < 0)
+       if (data == NULL || *data != 0x9c)      /* SBC syncword */
                return;
 
-       if (data == NULL || *data != 0x9c)      /* SBC syncword */
+       if (sbc_init(&sbc, 0) < 0)
                return;
 
        aux = g_new(guint8, 32);

We might want to have this fix inside sbc_init instead since others projects like pulseaudio may run into the same problem, also I guess it is a good practice to free any data allocated when returning an error.

Signature · 2 lines
Luiz Augusto von Dentz
Computer Engineer
#2 lore raw

Hi,

Quoted 30 lines · Luiz Augusto von Dentz

Hi,

Quoted 27 lines · On Wed, Jun 23, 2010 at 10:10 PM,  <[email protected]> wrote:

From: Harri Mahonen <[email protected]>

sbc structure gets leaked each time when there is no data or SBC syncword, because sbc_finalize is not called. Call sbc_init after checking the data for syncword.

---
 audio/gstbluetooth.c |    4 ++--

 1 files changed, 2 insertions(+), 2 deletions(-)
audio/gstbluetooth.c +2 -2
index 26dd4a5..11aefd7 100644
@@ -50,10 +50,10 @@ static void sbc_typefind(GstTypeFind *tf, gpointer ignore)
        sbc_t sbc;
        guint8 *data = gst_type_find_peek(tf, 0, 32);
 
-       if (sbc_init(&sbc, 0) < 0)
+       if (data == NULL || *data != 0x9c)      /* SBC syncword */
                return;
 
-       if (data == NULL || *data != 0x9c)      /* SBC syncword */
+       if (sbc_init(&sbc, 0) < 0)
                return;
 
Quoted 6 lines

audio/gstbluetooth.c static void sbc_typefind(GstTypeFind *tf, gpointer ignore) · line 59

Quoted 1 line
audio/gstbluetooth.c +0 -0
        aux = g_new(guint8, 32);

We might want to have this fix inside sbc_init instead since others projects like pulseaudio may run into the same problem, also I guess it is a good practice to free any data allocated when returning an error.

Sorry, I misunderstood the problem, it is really gstreamer only issue, but I would suggest using the return of sbc_parse so we don't have to hardcode sbc sync word detection, something like the following:

audio/gstbluetooth.c +9 -7
index 26dd4a5..9930820 100644
@@ -50,21 +50,24 @@ static void sbc_typefind(GstTypeFind *tf, gpointer ignore)
        sbc_t sbc;
        guint8 *data = gst_type_find_peek(tf, 0, 32);
 
-       if (sbc_init(&sbc, 0) < 0)
+       if (data == NULL)
                return;
 
-       if (data == NULL || *data != 0x9c)      /* SBC syncword */
+       if (sbc_init(&sbc, 0) < 0)
                return;
 
        aux = g_new(guint8, 32);
        memcpy(aux, data, 32);
-       sbc_parse(&sbc, aux, 32);
-       g_free(aux);
-       caps = gst_sbc_parse_caps_from_sbc(&sbc);
-       sbc_finish(&sbc);
+       if (sbc_parse(&sbc, aux, 32) < 0)
+               goto done;
 
+       caps = gst_sbc_parse_caps_from_sbc(&sbc);
        gst_type_find_suggest(tf, GST_TYPE_FIND_POSSIBLE, caps);
        gst_caps_unref(caps);
+
+done:
+       g_free(aux);
+       sbc_finish(&sbc);
 }
 
-- 

Luiz Augusto von Dentz
Computer Engineer

#3 lore raw
Quoted 3 lines · Luiz Augusto von Dentz

Sorry, I misunderstood the problem, it is really gstreamer only issue, but I would suggest using the return of sbc_parse so we don't have to hardcode sbc sync word detection, something like the following:

Thank you for your comments, I agree with using sbc_parse to avoid hardcoded sbc sync word detection. I'll repost updated patch.

Br,
Harri