[vlc-devel] [PATCH] input/item: input_item_AddOption: do not add NULL on error

Filip Roséen filip at atch.se
Thu May 18 12:19:29 CEST 2017


Implementations querying p_input->ppsz_options rely on each entry not
being NULL, meaning that we shall not add such values to the array.

These changes make sure that we check whether the strdup was
successful, and return an error if it was not.
---
 src/input/item.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/input/item.c b/src/input/item.c
index 7981059612..43da98acd3 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -572,11 +572,21 @@ int input_item_AddOption( input_item_t *p_input, const char *psz_option,
         err = VLC_ENOMEM;
         goto out;
     }
+
     p_input->optflagv = flagv;
-    flagv[p_input->optflagc++] = flags;
+
+    char* psz_option_dup = strdup( psz_option );
+    if( unlikely( !psz_option_dup ) )
+    {
+        err = VLC_ENOMEM;
+        goto out;
+    }
 
     INSERT_ELEM( p_input->ppsz_options, p_input->i_options,
-                 p_input->i_options, strdup( psz_option ) );
+                 p_input->i_options, psz_option_dup );
+
+    flagv[p_input->optflagc++] = flags;
+
 out:
     vlc_mutex_unlock( &p_input->lock );
     return err;
-- 
2.12.2


More information about the vlc-devel mailing list