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

Filip Roséen filip at atch.se
Wed Mar 1 09:52:08 CET 2017


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).
---
 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 9f0d0e1ad7..adff5ad3b2 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 )
         {
-- 
2.12.0



More information about the vlc-devel mailing list