Use STRDUP for error checking in more places

Use STRDUP() over strdup() to catch memory allocation errors.

There are still some instances of strdup left, but these are in functions
that currently have no error path and would require a larger rework.

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Allan McRae 2020-04-13 17:39:35 +10:00
parent 1b32897453
commit 0eda92c5d4
3 changed files with 10 additions and 5 deletions

View file

@ -201,11 +201,15 @@ static int parse_descfile(alpm_handle_t *handle, struct archive *a, alpm_pkg_t *
} else if(strcmp(key, "pkgdesc") == 0) {
STRDUP(newpkg->desc, ptr, return -1);
} else if(strcmp(key, "group") == 0) {
newpkg->groups = alpm_list_add(newpkg->groups, strdup(ptr));
char *tmp = NULL;
STRDUP(tmp, ptr, return -1);
newpkg->groups = alpm_list_add(newpkg->groups, tmp);
} else if(strcmp(key, "url") == 0) {
STRDUP(newpkg->url, ptr, return -1);
} else if(strcmp(key, "license") == 0) {
newpkg->licenses = alpm_list_add(newpkg->licenses, strdup(ptr));
char *tmp = NULL;
STRDUP(tmp, ptr, return -1);
newpkg->licenses = alpm_list_add(newpkg->licenses, tmp);
} else if(strcmp(key, "builddate") == 0) {
newpkg->builddate = _alpm_parsedate(ptr);
} else if(strcmp(key, "packager") == 0) {
@ -660,7 +664,7 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
/* internal fields for package struct */
newpkg->origin = ALPM_PKG_FROM_FILE;
newpkg->origin_data.file = strdup(pkgfile);
STRDUP(newpkg->origin_data.file, pkgfile, goto error);
newpkg->ops = get_file_pkg_ops();
newpkg->handle = handle;
newpkg->infolevel = INFRQ_BASE | INFRQ_DESC | INFRQ_SCRIPTLET;

View file

@ -105,7 +105,7 @@ int _alpm_handle_lock(alpm_handle_t *handle)
ASSERT(handle->lockfd < 0, return 0);
/* create the dir of the lockfile first */
dir = strdup(handle->lockfile);
STRDUP(dir, handle->lockfile, return -1);
ptr = strrchr(dir, '/');
if(ptr) {
*ptr = '\0';

View file

@ -350,7 +350,8 @@ int _alpm_unpack(alpm_handle_t *handle, const char *path, const char *prefix,
/* If specific files were requested, skip entries that don't match. */
if(list) {
char *entry_prefix = strdup(entryname);
char *entry_prefix = NULL;
STRDUP(entry_prefix, entryname, ret = 1; goto cleanup);
char *p = strstr(entry_prefix,"/");
if(p) {
*(p + 1) = '\0';