[vlc-commits] misc/text_style: text_segment_Copy: prevent memory-leak

Filip Roséen git at videolan.org
Wed Mar 1 17:43:20 CET 2017


vlc | branch: master | Filip Roséen <filip at atch.se> | Wed Mar  1 09:52:08 2017 +0100| [9b4cfefb98a022601567742441665e791d8f0e6b] | committer: Jean-Baptiste Kempf

misc/text_style: text_segment_Copy: prevent memory-leak

If text_segment_New is successful at least once, and then unsuccessful
two times in a row we would lose the pointer to the first allocated
object (meaning that it would leak).

This patch fixes the issue by aborting the loop as soon as we
encounter an error (if any).

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 src/misc/text_style.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/misc/text_style.c b/src/misc/text_style.c
index 9f0d0e1..adff5ad 100644
--- a/src/misc/text_style.c
+++ b/src/misc/text_style.c
@@ -210,8 +210,11 @@ text_segment_t *text_segment_Copy( text_segment_t *p_src )
 
     while( p_src ) {
         text_segment_t *p_new = text_segment_New( p_src->psz_text );
-        if( p_new )
-            p_new->style = text_style_Duplicate( p_src->style );
+
+        if( unlikely( !p_new ) )
+            break;
+
+        p_new->style = text_style_Duplicate( p_src->style );
 
         if( p_dst == NULL )
         {



More information about the vlc-commits mailing list