summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2020-04-13 09:39:35 +0200
committerAllan McRae <allan@archlinux.org>2020-04-13 15:44:46 +0200
commit0eda92c5d4f8810a68066ee72713ffdfa878dd8c (patch)
treef53a8c8730ef5833454b501eccedbfc0dd2e8c43 /lib
parent1b3289745334ec31507a12b6c54b2883a521543e (diff)
downloadpacman-0eda92c5d4f8810a68066ee72713ffdfa878dd8c.tar.gz
pacman-0eda92c5d4f8810a68066ee72713ffdfa878dd8c.tar.xz
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/be_package.c10
-rw-r--r--lib/libalpm/handle.c2
-rw-r--r--lib/libalpm/util.c3
3 files changed, 10 insertions, 5 deletions
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index 4832966b..38ba365d 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -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;
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index fc7c1faf..6b19a703 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -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';
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index cebc87ec..cb838e43 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -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';