[pacman-dev] [PATCH 3/6] Be consistent with memory treatment for plural option setters

Dan McGee dan at archlinux.org
Fri Jun 3 18:40:59 EDT 2011


In all cases we should duplicate the passed-in list so the caller is
free to do with it as it pleases.

Signed-off-by: Dan McGee <dan at archlinux.org>
---
 lib/libalpm/handle.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index 0b0db2f..d794992 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -400,17 +400,17 @@ int SYMEXPORT alpm_option_add_cachedir(const char *cachedir)
 
 int SYMEXPORT alpm_option_set_cachedirs(alpm_list_t *cachedirs)
 {
-	alpm_list_t *i, *new_cachedirs = NULL;
+	alpm_list_t *i;
 	ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+	if(handle->cachedirs){
+		FREELIST(handle->cachedirs);
+	}
 	for(i = cachedirs; i; i = i->next) {
 		int ret = alpm_option_add_cachedir(i->data);
 		if(ret) {
 			return ret;
 		}
 	}
-	if(handle->cachedirs) FREELIST(handle->cachedirs);
-	handle->cachedirs = new_cachedirs;
-	FREELIST(cachedirs);
 	return 0;
 }
 
@@ -496,7 +496,7 @@ int SYMEXPORT alpm_option_set_noupgrades(alpm_list_t *noupgrade)
 {
 	ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
 	if(handle->noupgrade) FREELIST(handle->noupgrade);
-	handle->noupgrade = noupgrade;
+	handle->noupgrade = alpm_list_strdup(noupgrade);
 	return 0;
 }
 
@@ -523,7 +523,7 @@ int SYMEXPORT alpm_option_set_noextracts(alpm_list_t *noextract)
 {
 	ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
 	if(handle->noextract) FREELIST(handle->noextract);
-	handle->noextract = noextract;
+	handle->noextract = alpm_list_strdup(noextract);
 	return 0;
 }
 
@@ -550,7 +550,7 @@ int SYMEXPORT alpm_option_set_ignorepkgs(alpm_list_t *ignorepkgs)
 {
 	ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
 	if(handle->ignorepkg) FREELIST(handle->ignorepkg);
-	handle->ignorepkg = ignorepkgs;
+	handle->ignorepkg = alpm_list_strdup(ignorepkgs);
 	return 0;
 }
 
@@ -577,7 +577,7 @@ int SYMEXPORT alpm_option_set_ignoregrps(alpm_list_t *ignoregrps)
 {
 	ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
 	if(handle->ignoregrp) FREELIST(handle->ignoregrp);
-	handle->ignoregrp = ignoregrps;
+	handle->ignoregrp = alpm_list_strdup(ignoregrps);
 	return 0;
 }
 
-- 
1.7.5.2



More information about the pacman-dev mailing list