From 0f26e3aa5b91ffc0a5bef9a0f0bb9d40ec198407 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 16 Jun 2011 13:03:33 -0500 Subject: Correctly duplicate delta objects We were using copy_data before; this works for the struct itself but not the strings contained within. Fix it up by duplicating all the data as we do with our other structures. Signed-off-by: Dan McGee --- lib/libalpm/delta.c | 18 ++++++++++++++++-- lib/libalpm/delta.h | 1 + lib/libalpm/package.c | 4 +++- 3 files changed, 20 insertions(+), 3 deletions(-) (limited to 'lib/libalpm') diff --git a/lib/libalpm/delta.c b/lib/libalpm/delta.c index fed84f45..fc7a0f75 100644 --- a/lib/libalpm/delta.c +++ b/lib/libalpm/delta.c @@ -314,11 +314,25 @@ pmdelta_t *_alpm_delta_parse(char *line) void _alpm_delta_free(pmdelta_t *delta) { - FREE(delta->from); - FREE(delta->to); FREE(delta->delta); FREE(delta->delta_md5); + FREE(delta->from); + FREE(delta->to); FREE(delta); } +pmdelta_t *_alpm_delta_dup(const pmdelta_t *delta) +{ + pmdelta_t *newdelta; + CALLOC(newdelta, 1, sizeof(pmdelta_t), return NULL); + STRDUP(newdelta->delta, delta->delta, return NULL); + STRDUP(newdelta->delta_md5, delta->delta_md5, return NULL); + STRDUP(newdelta->from, delta->from, return NULL); + STRDUP(newdelta->to, delta->to, return NULL); + newdelta->delta_size = delta->delta_size; + newdelta->download_size = delta->download_size; + + return newdelta; +} + /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libalpm/delta.h b/lib/libalpm/delta.h index 87869256..6ac54139 100644 --- a/lib/libalpm/delta.h +++ b/lib/libalpm/delta.h @@ -28,6 +28,7 @@ pmdelta_t *_alpm_delta_parse(char *line); void _alpm_delta_free(pmdelta_t *delta); +pmdelta_t *_alpm_delta_dup(const pmdelta_t *delta); off_t _alpm_shortest_delta_path(pmhandle_t *handle, alpm_list_t *deltas, const char *to, alpm_list_t **path); diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index ff011982..0b0e9741 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -466,7 +466,9 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg) newpkg->optdepends = alpm_list_strdup(pkg->optdepends); newpkg->conflicts = alpm_list_strdup(pkg->conflicts); newpkg->provides = alpm_list_strdup(pkg->provides); - newpkg->deltas = alpm_list_copy_data(pkg->deltas, sizeof(pmdelta_t)); + for(i = pkg->deltas; i; i = alpm_list_next(i)) { + newpkg->deltas = alpm_list_add(newpkg->deltas, _alpm_delta_dup(i->data)); + } /* internal */ newpkg->infolevel = pkg->infolevel; -- cgit v1.2.3-70-g09d2