[vlc-devel] [PATCH] vlc_execve: fix fork() version from segfaulting and also endless loop

Keary Griffin kearygriffin at gmail.com
Fri Jun 11 03:52:33 CEST 2010


pp_data was freed near start of function, but never set to anything before call to vlc_execve:  Removed.
Added code to I/O loop, if there is no more data to read & no more data to write, end loop
---
 src/extras/libc.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/src/extras/libc.c b/src/extras/libc.c
index 1be7fe8..457e1d1 100644
--- a/src/extras/libc.c
+++ b/src/extras/libc.c
@@ -596,6 +596,7 @@ int vlc_execve( vlc_object_t *p_object, int i_argc, char *const *ppsz_argv,
 #ifdef HAVE_FORK
 # define BUFSIZE 1024
     int fds[2], i_status;
+    bool b_readFinished = false;
 
     if (socketpair (PF_LOCAL, SOCK_STREAM, 0, fds))
         return -1;
@@ -632,14 +633,12 @@ int vlc_execve( vlc_object_t *p_object, int i_argc, char *const *ppsz_argv,
     close (fds[1]);
 
     *pi_data = 0;
-    if (*pp_data)
-        free (*pp_data);
     *pp_data = NULL;
 
     if (i_in == 0)
         shutdown (fds[0], SHUT_WR);
 
-    while (!p_object->b_die)
+    while (!p_object->b_die && ( !b_readFinished || i_in > 0 ) )
     {
         struct pollfd ufd[1];
         memset (ufd, 0, sizeof (ufd));
@@ -666,6 +665,7 @@ int vlc_execve( vlc_object_t *p_object, int i_argc, char *const *ppsz_argv,
                 case -1:
                 case 0:
                     shutdown (fds[0], SHUT_RD);
+                    b_readFinished = true;
                     break;
 
                 default:
@@ -847,9 +847,6 @@ int vlc_execve( vlc_object_t *p_object, int i_argc, char *const *ppsz_argv,
 
     /* Read output from the child process. */
     *pi_data = 0;
-    if( *pp_data )
-        free( pp_data );
-    *pp_data = NULL;
     *pp_data = malloc( 1025 );  /* +1 for \0 */
 
     while ( !p_object->b_die )
-- 
1.7.0.4




More information about the vlc-devel mailing list