summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2008-01-11 01:00:15 -0600
committerDan McGee <dan@archlinux.org>2008-01-11 22:58:05 -0600
commit3e133524a54ab55daff666d26c67ac288b605e92 (patch)
treecc1f0080c28d65ab5c029659a653658c52d748a7
parentccc1c731529de16f6fa4064fd992a8f63d7cfc26 (diff)
downloadpacman-3e133524a54ab55daff666d26c67ac288b605e92.tar.xz
Add functions to manipulate pmdepend_t objects
We didn't have a free function before, causing some memory leaks. We also need a dup function now that strings are not in the structure but are dynamically allocated. Also adapt pmdepmissing_t to use a pointer to a depend struct instead of an inclusive one so we can use the functions we created here. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--lib/libalpm/deps.c53
-rw-r--r--lib/libalpm/deps.h8
-rw-r--r--lib/libalpm/package.c11
3 files changed, 44 insertions, 28 deletions
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index cc9a581f..d839c6b1 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -36,10 +36,19 @@
#include "cache.h"
#include "handle.h"
+void _alpm_dep_free(pmdepend_t *dep)
+{
+ FREE(dep->name);
+ FREE(dep->version);
+ FREE(dep);
+}
+
static pmgraph_t *_alpm_graph_new(void)
{
pmgraph_t *graph = NULL;
+ ALPM_LOG_FUNC;
+
MALLOC(graph, sizeof(pmgraph_t), RET_ERR(PM_ERR_MEMORY, NULL));
if(graph) {
@@ -59,8 +68,7 @@ static void _alpm_graph_free(void *data)
free(graph);
}
-pmdepmissing_t *_alpm_depmiss_new(const char *target, pmdepmod_t depmod,
- const char *depname, const char *depversion)
+pmdepmissing_t *_alpm_depmiss_new(const char *target, pmdepend_t *dep)
{
pmdepmissing_t *miss;
@@ -69,21 +77,14 @@ pmdepmissing_t *_alpm_depmiss_new(const char *target, pmdepmod_t depmod,
MALLOC(miss, sizeof(pmdepmissing_t), RET_ERR(PM_ERR_MEMORY, NULL));
STRDUP(miss->target, target, RET_ERR(PM_ERR_MEMORY, NULL));
- miss->depend.mod = depmod;
- STRDUP(miss->depend.name, depname, RET_ERR(PM_ERR_MEMORY, NULL));
- if(depversion) {
- STRDUP(miss->depend.version, depversion, RET_ERR(PM_ERR_MEMORY, NULL));
- }
+ miss->depend = _alpm_dep_dup(dep);
return(miss);
}
void _alpm_depmiss_free(pmdepmissing_t *miss)
{
- if(miss->depend.version && strlen(miss->depend.version) != 0) {
- FREE(miss->depend.version);
- }
- FREE(miss->depend.name);
+ _alpm_dep_free(miss->depend);
FREE(miss->target);
FREE(miss);
}
@@ -265,8 +266,7 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(pmdb_t *db, int reversedeps,
_alpm_log(PM_LOG_DEBUG, "checkdeps: missing dependency '%s' for package '%s'\n",
missdepstring, alpm_pkg_get_name(tp));
free(missdepstring);
- miss = _alpm_depmiss_new(alpm_pkg_get_name(tp), depend->mod,
- depend->name, depend->version);
+ miss = _alpm_depmiss_new(alpm_pkg_get_name(tp), depend);
baddeps = alpm_list_add(baddeps, miss);
}
}
@@ -292,8 +292,7 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(pmdb_t *db, int reversedeps,
_alpm_log(PM_LOG_DEBUG, "checkdeps: transaction would break '%s' dependency of '%s'\n",
missdepstring, alpm_pkg_get_name(lp));
free(missdepstring);
- miss = _alpm_depmiss_new(lp->name, depend->mod,
- depend->name, depend->version);
+ miss = _alpm_depmiss_new(lp->name, depend);
baddeps = alpm_list_add(baddeps, miss);
}
}
@@ -414,6 +413,18 @@ pmdepend_t SYMEXPORT *alpm_splitdep(const char *depstring)
return(depend);
}
+pmdepend_t *_alpm_dep_dup(const pmdepend_t *dep)
+{
+ pmdepend_t *newdep;
+ CALLOC(newdep, sizeof(pmdepend_t), 1, RET_ERR(PM_ERR_MEMORY, NULL));
+
+ STRDUP(newdep->name, dep->name, RET_ERR(PM_ERR_MEMORY, NULL));
+ STRDUP(newdep->version, dep->version, RET_ERR(PM_ERR_MEMORY, NULL));
+ newdep->mod = dep->mod;
+
+ return(newdep);
+}
+
/* These parameters are messy. We check if this package, given a list of
* targets and a db is safe to remove. We do NOT remove it if it is in the
* target list, or if if the package was explictly installed and
@@ -527,7 +538,7 @@ int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg,
for(i = deps; i; i = i->next) {
int found = 0;
pmdepmissing_t *miss = i->data;
- pmdepend_t *missdep = &(miss->depend);
+ pmdepend_t *missdep = alpm_miss_get_dep(miss);
pmpkg_t *sync = NULL;
/* check if one of the packages in *list already satisfies this dependency */
@@ -632,7 +643,7 @@ const char SYMEXPORT *alpm_miss_get_target(const pmdepmissing_t *miss)
/* Sanity checks */
ASSERT(miss != NULL, return(NULL));
- return miss->target;
+ return(miss->target);
}
pmdepend_t SYMEXPORT *alpm_miss_get_dep(pmdepmissing_t *miss)
@@ -642,7 +653,7 @@ pmdepend_t SYMEXPORT *alpm_miss_get_dep(pmdepmissing_t *miss)
/* Sanity checks */
ASSERT(miss != NULL, return(NULL));
- return &(miss->depend);
+ return(miss->depend);
}
pmdepmod_t SYMEXPORT alpm_dep_get_mod(const pmdepend_t *dep)
@@ -652,7 +663,7 @@ pmdepmod_t SYMEXPORT alpm_dep_get_mod(const pmdepend_t *dep)
/* Sanity checks */
ASSERT(dep != NULL, return(-1));
- return dep->mod;
+ return(dep->mod);
}
const char SYMEXPORT *alpm_dep_get_name(const pmdepend_t *dep)
@@ -662,7 +673,7 @@ const char SYMEXPORT *alpm_dep_get_name(const pmdepend_t *dep)
/* Sanity checks */
ASSERT(dep != NULL, return(NULL));
- return dep->name;
+ return(dep->name);
}
const char SYMEXPORT *alpm_dep_get_version(const pmdepend_t *dep)
@@ -672,7 +683,7 @@ const char SYMEXPORT *alpm_dep_get_version(const pmdepend_t *dep)
/* Sanity checks */
ASSERT(dep != NULL, return(NULL));
- return dep->version;
+ return(dep->version);
}
/** Reverse of splitdep; make a dep string from a pmdepend_t struct.
diff --git a/lib/libalpm/deps.h b/lib/libalpm/deps.h
index b20ea92f..debd5347 100644
--- a/lib/libalpm/deps.h
+++ b/lib/libalpm/deps.h
@@ -36,7 +36,7 @@ struct __pmdepend_t {
/* Missing dependency */
struct __pmdepmissing_t {
char *target;
- pmdepend_t depend;
+ pmdepend_t *depend;
};
/* Graphs */
@@ -48,8 +48,10 @@ struct __pmgraph_t {
alpm_list_t *childptr; /* points to a child in children list */
};
-pmdepmissing_t *_alpm_depmiss_new(const char *target, pmdepmod_t depmod,
- const char *depname, const char *depversion);
+
+void _alpm_dep_free(pmdepend_t *dep);
+pmdepend_t *_alpm_dep_dup(const pmdepend_t *dep);
+pmdepmissing_t *_alpm_depmiss_new(const char *target, pmdepend_t *dep);
void _alpm_depmiss_free(pmdepmissing_t *miss);
alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode);
void _alpm_recursedeps(pmdb_t *db, alpm_list_t *targs, int include_explicit);
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index a9652f25..7e1bcd55 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -771,6 +771,7 @@ pmpkg_t *_alpm_pkg_new(const char *name, const char *version)
pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg)
{
pmpkg_t *newpkg;
+ alpm_list_t *i;
ALPM_LOG_FUNC;
@@ -792,13 +793,14 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg)
newpkg->force = pkg->force;
newpkg->reason = pkg->reason;
- newpkg->licenses = alpm_list_strdup(alpm_pkg_get_licenses(pkg));
+ newpkg->licenses = alpm_list_strdup(alpm_pkg_get_licenses(pkg));
newpkg->replaces = alpm_list_strdup(alpm_pkg_get_replaces(pkg));
newpkg->groups = alpm_list_strdup(alpm_pkg_get_groups(pkg));
newpkg->files = alpm_list_strdup(alpm_pkg_get_files(pkg));
newpkg->backup = alpm_list_strdup(alpm_pkg_get_backup(pkg));
- newpkg->depends = alpm_list_copy_data(alpm_pkg_get_depends(pkg),
- sizeof(pmdepend_t));
+ for(i = alpm_pkg_get_depends(pkg); i; i = alpm_list_next(i)) {
+ newpkg->depends = alpm_list_add(newpkg->depends, _alpm_dep_dup(i->data));
+ }
newpkg->optdepends = alpm_list_strdup(alpm_pkg_get_optdepends(pkg));
newpkg->conflicts = alpm_list_strdup(alpm_pkg_get_conflicts(pkg));
newpkg->provides = alpm_list_strdup(alpm_pkg_get_provides(pkg));
@@ -838,7 +840,8 @@ void _alpm_pkg_free(pmpkg_t *pkg)
FREELIST(pkg->groups);
FREELIST(pkg->files);
FREELIST(pkg->backup);
- FREELIST(pkg->depends);
+ alpm_list_free_inner(pkg->depends, (alpm_list_fn_free)_alpm_dep_free);
+ alpm_list_free(pkg->depends);
FREELIST(pkg->optdepends);
FREELIST(pkg->conflicts);
FREELIST(pkg->provides);