Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/deps.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/deps.c')
-rw-r--r--lib/libalpm/deps.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index f2ee8f41..daab9c3f 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -1,7 +1,7 @@
/*
* deps.c
*
- * Copyright (c) 2006-2014 Pacman Development Team <pacman-dev@archlinux.org>
+ * Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org>
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
* Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
* Copyright (c) 2005, 2006 by Miklos Vajna <vmiklos@frugalware.org>
@@ -48,13 +48,17 @@ static alpm_depmissing_t *depmiss_new(const char *target, alpm_depend_t *dep,
{
alpm_depmissing_t *miss;
- MALLOC(miss, sizeof(alpm_depmissing_t), return NULL);
+ CALLOC(miss, 1, sizeof(alpm_depmissing_t), return NULL);
- STRDUP(miss->target, target, return NULL);
+ STRDUP(miss->target, target, goto error);
miss->depend = _alpm_dep_dup(dep);
- STRDUP(miss->causingpkg, causingpkg, return NULL);
+ STRDUP(miss->causingpkg, causingpkg, goto error);
return miss;
+
+error:
+ alpm_depmissing_free(miss);
+ return NULL;
}
void SYMEXPORT alpm_depmissing_free(alpm_depmissing_t *miss)
@@ -465,11 +469,11 @@ alpm_depend_t SYMEXPORT *alpm_dep_from_string(const char *depstring)
return NULL;
}
- MALLOC(depend, sizeof(alpm_depend_t), return NULL);
+ CALLOC(depend, 1, sizeof(alpm_depend_t), return NULL);
/* Note the extra space in ": " to avoid matching the epoch */
if((desc = strstr(depstring, ": ")) != NULL) {
- STRDUP(depend->desc, desc + 2, return NULL);
+ STRDUP(depend->desc, desc + 2, goto error);
deplen = desc - depstring;
} else {
/* no description- point desc at NULL at end of string for later use */
@@ -509,13 +513,17 @@ alpm_depend_t SYMEXPORT *alpm_dep_from_string(const char *depstring)
}
/* copy the right parts to the right places */
- STRNDUP(depend->name, depstring, ptr - depstring, return NULL);
+ STRNDUP(depend->name, depstring, ptr - depstring, goto error);
depend->name_hash = _alpm_hash_sdbm(depend->name);
if(version) {
- STRNDUP(depend->version, version, desc - version, return NULL);
+ STRNDUP(depend->version, version, desc - version, goto error);
}
return depend;
+
+error:
+ alpm_dep_free(depend);
+ return NULL;
}
alpm_depend_t *_alpm_dep_dup(const alpm_depend_t *dep)
@@ -523,13 +531,17 @@ alpm_depend_t *_alpm_dep_dup(const alpm_depend_t *dep)
alpm_depend_t *newdep;
CALLOC(newdep, 1, sizeof(alpm_depend_t), return NULL);
- STRDUP(newdep->name, dep->name, return NULL);
- STRDUP(newdep->version, dep->version, return NULL);
- STRDUP(newdep->desc, dep->desc, return NULL);
+ STRDUP(newdep->name, dep->name, goto error);
+ STRDUP(newdep->version, dep->version, goto error);
+ STRDUP(newdep->desc, dep->desc, goto error);
newdep->name_hash = dep->name_hash;
newdep->mod = dep->mod;
return newdep;
+
+error:
+ alpm_dep_free(newdep);
+ return NULL;
}
/* These parameters are messy. We check if this package, given a list of
@@ -597,11 +609,13 @@ int _alpm_recursedeps(alpm_db_t *db, alpm_list_t **targs, int include_explicit)
alpm_pkg_t *deppkg = j->data;
if(_alpm_pkg_depends_on(pkg, deppkg)
&& can_remove_package(db, deppkg, *targs, include_explicit)) {
- alpm_pkg_t *copy;
+ alpm_pkg_t *copy = NULL;
_alpm_log(db->handle, ALPM_LOG_DEBUG, "adding '%s' to the targets\n",
deppkg->name);
/* add it to the target list */
if(_alpm_pkg_dup(deppkg, &copy)) {
+ /* we return memory on "non-fatal" error in _alpm_pkg_dup */
+ _alpm_pkg_free(copy);
return -1;
}
*targs = alpm_list_add(*targs, copy);