From 3e133524a54ab55daff666d26c67ac288b605e92 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 11 Jan 2008 01:00:15 -0600 Subject: 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 --- lib/libalpm/package.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'lib/libalpm/package.c') 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); -- cgit v1.2.3-54-g00ecf