[vlc-commits] decomp: fix leak on error and clean up a little

Rémi Denis-Courmont git at videolan.org
Tue Apr 16 20:22:11 CEST 2013


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Apr 16 21:17:39 2013 +0300| [655100aa02638c1fe52575c93c5cb72653e0554b] | committer: Rémi Denis-Courmont

decomp: fix leak on error and clean up a little

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

 modules/stream_filter/decomp.c |   30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/modules/stream_filter/decomp.c b/modules/stream_filter/decomp.c
index 82bb5e9..20075a8 100644
--- a/modules/stream_filter/decomp.c
+++ b/modules/stream_filter/decomp.c
@@ -71,11 +71,17 @@ vlc_module_end ()
 
 struct stream_sys_t
 {
-    block_t      *peeked;
-    uint64_t     offset;
+    /* Thread data */
+    int          write_fd;
+
+    /* Caller data */
     vlc_thread_t thread;
     pid_t        pid;
-    int          write_fd, read_fd;
+
+    uint64_t     offset;
+    block_t      *peeked;
+
+    int          read_fd;
     bool         can_pace;
 };
 
@@ -146,7 +152,7 @@ static void *Thread (void *data)
     }
     while (!error);
 
-    msg_Dbg (stream, "compressed stream at EOF");
+    msg_Err (stream, "compressed stream at EOF");
     /* Let child process know about EOF */
     p_sys->write_fd = -1;
     close (fd);
@@ -277,9 +283,10 @@ static int Open (stream_t *stream, const char *path)
     stream->pf_read = Read;
     stream->pf_peek = Peek;
     stream->pf_control = Control;
-    p_sys->peeked = NULL;
-    p_sys->offset = 0;
+
     p_sys->pid = -1;
+    p_sys->offset = 0;
+    p_sys->peeked = NULL;
     stream_Control (stream->p_source, STREAM_CAN_CONTROL_PACE,
                     &p_sys->can_pace);
 
@@ -344,12 +351,15 @@ static int Open (stream_t *stream, const char *path)
         }
         close (comp[0]);
         if (ret != VLC_SUCCESS)
-        {
             close (comp[1]);
-            if (p_sys->pid != -1)
-                while (waitpid (p_sys->pid, &(int){ 0 }, 0) == -1);
-        }
     }
+
+    if (ret == VLC_SUCCESS)
+        return VLC_SUCCESS;
+
+    if (p_sys->pid != -1)
+        while (waitpid (p_sys->pid, &(int){ 0 }, 0) == -1);
+    free (p_sys);
     return ret;
 }
 



More information about the vlc-commits mailing list