[vlc-commits] udp: avoid alloc/free on I/O error

Rémi Denis-Courmont git at videolan.org
Tue Mar 17 19:51:53 CET 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Mar 17 19:41:04 2015 +0200| [efc27f360357ee8ae65f64d20dd5e3d1e7280fa0] | committer: Rémi Denis-Courmont

udp: avoid alloc/free on I/O error

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

 modules/access/udp.c |   29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/modules/access/udp.c b/modules/access/udp.c
index 1a17629..3ba94bd 100644
--- a/modules/access/udp.c
+++ b/modules/access/udp.c
@@ -252,30 +252,27 @@ static void* ThreadRead( void *data )
 
     for( ;; )
     {
-        block_t *pkt;
-        ssize_t len;
-
-        block_FifoPace( sys->fifo, SIZE_MAX, sys->fifo_size );
-
-        pkt = block_Alloc( MTU );
-        if( unlikely( pkt == NULL ) )
+        block_t *pkt = block_Alloc(MTU);
+        if (unlikely(pkt == NULL))
             break;
 
-        block_cleanup_push( pkt );
-        len = net_Read( access, sys->fd, NULL, pkt->p_buffer, MTU, false );
+        ssize_t len;
+
+        block_cleanup_push(pkt);
+        do
+            len = net_Read(access, sys->fd, NULL, pkt->p_buffer, MTU, false);
+        while (len == -1 && errno != EINTR);
         vlc_cleanup_pop();
 
-        if( len == -1 )
+        if (len == -1)
         {
-            block_Release( pkt );
-
-            if( errno == EINTR )
-                break;
-            continue;
+            block_Release(pkt);
+            break;
         }
 
         pkt->i_buffer = len;
-        block_FifoPut( sys->fifo, pkt );
+        block_FifoPace(sys->fifo, SIZE_MAX, sys->fifo_size - len);
+        block_FifoPut(sys->fifo, pkt);
     }
 
     block_FifoWake( sys->fifo );



More information about the vlc-commits mailing list