[vlc-commits] commit: rtp sout: fix memleak (Pierre Ynard )

git at videolan.org git at videolan.org
Wed Dec 1 03:01:59 CET 2010


vlc | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Wed Dec  1 03:01:44 2010 +0100| [c0b04d59808d57997baebcf26ab4efb527160e2a] | committer: Pierre Ynard 

rtp sout: fix memleak

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c0b04d59808d57997baebcf26ab4efb527160e2a
---

 modules/stream_out/rtpfmt.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c
index 20ae567..567f9e8 100644
--- a/modules/stream_out/rtpfmt.c
+++ b/modules/stream_out/rtpfmt.c
@@ -67,7 +67,10 @@ static int rtp_vorbis_pack_headers(size_t room, void *p_extra, size_t i_extra,
     if (val != VLC_SUCCESS)
         return val;
     if (packet_count < 3)
-        return VLC_EGENERIC;
+    {
+        val = VLC_EGENERIC;
+        goto free;
+    }
 
     unsigned length_size[2] = { 0, 0 };
     for (int i = 0; i < 2; i++)
@@ -84,7 +87,10 @@ static int rtp_vorbis_pack_headers(size_t room, void *p_extra, size_t i_extra,
                 + packet_size[0] + packet_size[1] + packet_size[2];
     *p_buffer = malloc(*i_buffer);
     if (*p_buffer == NULL)
-        return VLC_ENOMEM;
+    {
+        val = VLC_ENOMEM;
+        goto free;
+    }
 
     uint8_t *p = *p_buffer + room;
     /* Number of headers */
@@ -104,11 +110,15 @@ static int rtp_vorbis_pack_headers(size_t room, void *p_extra, size_t i_extra,
     for (int i = 0; i < 3; i++)
     {
         memcpy(p, packet[i], packet_size[i]);
-        free(packet[i]);
         p += packet_size[i];
     }
 
-    return VLC_SUCCESS;
+    val = VLC_SUCCESS;
+free:
+    for (unsigned i = 0; i < packet_count; i++)
+        free(packet[i]);
+
+    return val;
 }
 
 static void sprintf_hexa( char *s, uint8_t *p_data, int i_data )



More information about the vlc-commits mailing list