[vlc-commits] core: config: config_ListModules: don't use xstrdup/xmalloc
Hugo Beauzée-Luyssen
git at videolan.org
Wed Aug 22 11:44:37 CEST 2018
vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Tue Aug 21 17:02:50 2018 +0200| [eb7a3d08d48e1f5438204c73d5d82c6d0bf7d99e] | committer: Hugo Beauzée-Luyssen
core: config: config_ListModules: don't use xstrdup/xmalloc
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=eb7a3d08d48e1f5438204c73d5d82c6d0bf7d99e
---
src/config/core.c | 50 ++++++++++++++++++++++++++++++++++++++------------
1 file changed, 38 insertions(+), 12 deletions(-)
diff --git a/src/config/core.c b/src/config/core.c
index 430aadf9cf..8deba34101 100644
--- a/src/config/core.c
+++ b/src/config/core.c
@@ -262,26 +262,52 @@ static ssize_t config_ListModules (const char *cap, char ***restrict values,
return n;
}
- char **vals = xmalloc ((n + 2) * sizeof (*vals));
- char **txts = xmalloc ((n + 2) * sizeof (*txts));
+ char **vals = malloc ((n + 2) * sizeof (*vals));
+ char **txts = malloc ((n + 2) * sizeof (*txts));
+ if (!vals || !txts)
+ {
+ free (vals);
+ free (txts);
+ *values = *texts = NULL;
+ return -1;
+ }
- vals[0] = xstrdup ("any");
- txts[0] = xstrdup (_("Automatic"));
+ ssize_t i = 0;
- for (ssize_t i = 0; i < n; i++)
+ vals[i] = strdup ("any");
+ txts[i] = strdup (_("Automatic"));
+ if (!vals[i] || !txts[i])
+ goto error;
+
+ ++i;
+ for (; i <= n; i++)
{
- vals[i + 1] = xstrdup (module_get_object (list[i]));
- txts[i + 1] = xstrdup (module_gettext (list[i],
- module_get_name (list[i], true)));
+ vals[i] = strdup (module_get_object (list[i - 1]));
+ txts[i] = strdup (module_gettext (list[i - 1],
+ module_get_name (list[i - 1], true)));
+ if( !vals[i] || !txts[i])
+ goto error;
}
-
- vals[n + 1] = xstrdup ("none");
- txts[n + 1] = xstrdup (_("Disable"));
+ vals[i] = strdup ("none");
+ txts[i] = strdup (_("Disable"));
+ if( !vals[i] || !txts[i])
+ goto error;
*values = vals;
*texts = txts;
module_list_free (list);
- return n + 2;
+ return i + 1;
+
+error:
+ for (ssize_t j = 0; j <= i; ++j)
+ {
+ free (vals[j]);
+ free (txts[j]);
+ }
+ free(vals);
+ free(txts);
+ *values = *texts = NULL;
+ return -1;
}
ssize_t config_GetPszChoices(const char *name,
More information about the vlc-commits
mailing list