[pacman-dev] [PATCH] _alpm_delta_dup: free memory on error
Signed-off-by: Allan McRae <allan@archlinux.org> --- lib/libalpm/delta.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/libalpm/delta.c b/lib/libalpm/delta.c index baa02b7..23ca31d 100644 --- a/lib/libalpm/delta.c +++ b/lib/libalpm/delta.c @@ -342,14 +342,18 @@ alpm_delta_t *_alpm_delta_dup(const alpm_delta_t *delta) { alpm_delta_t *newdelta; CALLOC(newdelta, 1, sizeof(alpm_delta_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); + STRDUP(newdelta->delta, delta->delta, goto error); + STRDUP(newdelta->delta_md5, delta->delta_md5, goto error); + STRDUP(newdelta->from, delta->from, goto error); + STRDUP(newdelta->to, delta->to, goto error); newdelta->delta_size = delta->delta_size; newdelta->download_size = delta->download_size; return newdelta; + +error: + _alpm_delta_free(newdelta); + return NULL; } /* vim: set noet: */ -- 2.2.0
Signed-off-by: Allan McRae <allan@archlinux.org> --- lib/libalpm/deps.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index f2ee8f4..ca36270 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -50,11 +50,15 @@ static alpm_depmissing_t *depmiss_new(const char *target, alpm_depend_t *dep, MALLOC(miss, 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) -- 2.2.0
participants (1)
-
Allan McRae