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

Filip Roséen git at videolan.org
Thu May 18 18:09:35 CEST 2017


vlc | branch: master | Filip Roséen <filip at atch.se> | Thu May 18 12:19:29 2017 +0200| [ef7820be8d1790f04ee7ee5b10a30c83ded4c6c1] | committer: Rémi Denis-Courmont

input/item: input_item_AddOption: do not add NULL on error

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.

Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>

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

 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 83e0ae4f7d..756c5e7ec8 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -559,11 +559,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;



More information about the vlc-commits mailing list