[vlc-commits] core: config: Remove remaining calls to xmalloc/xstrdup
Hugo Beauzée-Luyssen
git at videolan.org
Wed Aug 22 11:44:38 CEST 2018
vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Tue Aug 21 18:31:07 2018 +0200| [df7a0f02fce83065ad36b52192543add66bed983] | committer: Hugo Beauzée-Luyssen
core: config: Remove remaining calls to xmalloc/xstrdup
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=df7a0f02fce83065ad36b52192543add66bed983
---
src/config/core.c | 31 ++++++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/config/core.c b/src/config/core.c
index 8deba34101..0c9e4184f5 100644
--- a/src/config/core.c
+++ b/src/config/core.c
@@ -349,20 +349,41 @@ ssize_t config_GetPszChoices(const char *name,
return cfg->list.psz_cb(name, values, texts);
}
- char **vals = xmalloc (sizeof (*vals) * count);
- char **txts = xmalloc (sizeof (*txts) * count);
+ char **vals = malloc (sizeof (*vals) * count);
+ char **txts = malloc (sizeof (*txts) * count);
+ if (!vals || !txts)
+ {
+ free (vals);
+ free (txts);
+ errno = ENOMEM;
+ return -1;
+ }
- for (size_t i = 0; i < count; i++)
+ size_t i;
+ for (i = 0; i < count; i++)
{
- vals[i] = xstrdup ((cfg->list.psz[i] != NULL) ? cfg->list.psz[i] : "");
+ vals[i] = strdup ((cfg->list.psz[i] != NULL) ? cfg->list.psz[i] : "");
/* FIXME: use module_gettext() instead */
- txts[i] = xstrdup ((cfg->list_text[i] != NULL)
+ txts[i] = strdup ((cfg->list_text[i] != NULL)
? vlc_gettext (cfg->list_text[i]) : "");
+ if (!vals[i] || !txts[i])
+ goto error;
}
*values = vals;
*texts = txts;
return count;
+
+error:
+ for (size_t j = 0; j <= i; ++j)
+ {
+ free (vals[j]);
+ free (txts[j]);
+ }
+ free(vals);
+ free(txts);
+ errno = ENOMEM;
+ return -1;
}
static int confcmp (const void *a, const void *b)
More information about the vlc-commits
mailing list