[pacman-dev] [PATCH 8/8] alpm: export *_free functions

Andrew Gregory andrew.gregory.8 at gmail.com
Mon Jan 6 11:52:27 EST 2014


Front-ends should be able to free memory that alpm hands them.

Signed-off-by: Andrew Gregory <andrew.gregory.8 at gmail.com>
---
 lib/libalpm/alpm.h     |  4 ++++
 lib/libalpm/conflict.c |  6 +++---
 lib/libalpm/conflict.h |  3 ---
 lib/libalpm/deps.c     |  8 ++++----
 lib/libalpm/deps.h     |  1 -
 lib/libalpm/remove.c   |  6 +++---
 lib/libalpm/sync.c     | 14 +++++++-------
 src/pacman/remove.c    |  3 ++-
 src/pacman/sync.c      | 13 ++++++++-----
 9 files changed, 31 insertions(+), 27 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 5628527..28ae851 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -1351,6 +1351,10 @@ enum alpm_caps {
 const char *alpm_version(void);
 enum alpm_caps alpm_capabilities(void);
 
+void alpm_fileconflict_free(alpm_fileconflict_t *conflict);
+void alpm_depmiss_free(alpm_depmissing_t *miss);
+void alpm_conflict_free(alpm_conflict_t *conflict);
+
 /* End of alpm_api */
 /** @} */
 
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index 5a6e2be..4a1d77e 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -62,7 +62,7 @@ static alpm_conflict_t *conflict_new(alpm_pkg_t *pkg1, alpm_pkg_t *pkg2,
 /**
  * @brief Free a conflict and its members.
  */
-void _alpm_conflict_free(alpm_conflict_t *conflict)
+void SYMEXPORT alpm_conflict_free(alpm_conflict_t *conflict)
 {
 	FREE(conflict->package2);
 	FREE(conflict->package1);
@@ -135,7 +135,7 @@ static int add_conflict(alpm_handle_t *handle, alpm_list_t **baddeps,
 				pkg1->name, pkg2->name, conflict_str);
 		free(conflict_str);
 	} else {
-		_alpm_conflict_free(conflict);
+		alpm_conflict_free(conflict);
 	}
 	return 0;
 }
@@ -290,7 +290,7 @@ error:
 /**
  * @brief Frees a conflict and its members.
  */
-void _alpm_fileconflict_free(alpm_fileconflict_t *conflict)
+void SYMEXPORT alpm_fileconflict_free(alpm_fileconflict_t *conflict)
 {
 	FREE(conflict->ctarget);
 	FREE(conflict->file);
diff --git a/lib/libalpm/conflict.h b/lib/libalpm/conflict.h
index f7a667d..182eb0e 100644
--- a/lib/libalpm/conflict.h
+++ b/lib/libalpm/conflict.h
@@ -25,14 +25,11 @@
 #include "package.h"
 
 alpm_conflict_t *_alpm_conflict_dup(const alpm_conflict_t *conflict);
-void _alpm_conflict_free(alpm_conflict_t *conflict);
 alpm_list_t *_alpm_innerconflicts(alpm_handle_t *handle, alpm_list_t *packages);
 alpm_list_t *_alpm_outerconflicts(alpm_db_t *db, alpm_list_t *packages);
 alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
 		alpm_list_t *upgrade, alpm_list_t *remove);
 
-void _alpm_fileconflict_free(alpm_fileconflict_t *conflict);
-
 #endif /* _ALPM_CONFLICT_H */
 
 /* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 1f6ad11..7ee3ee4 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -57,7 +57,7 @@ static alpm_depmissing_t *depmiss_new(const char *target, alpm_depend_t *dep,
 	return miss;
 }
 
-void _alpm_depmiss_free(alpm_depmissing_t *miss)
+void SYMEXPORT alpm_depmiss_free(alpm_depmissing_t *miss)
 {
 	_alpm_dep_free(miss->depend);
 	FREE(miss->target);
@@ -804,7 +804,7 @@ int _alpm_resolvedeps(alpm_handle_t *handle, alpm_list_t *localpkgs,
 		/* check if one of the packages in the [*packages] list already satisfies
 		 * this dependency */
 		if(find_dep_satisfier(*packages, missdep)) {
-			_alpm_depmiss_free(miss);
+			alpm_depmiss_free(miss);
 			continue;
 		}
 		/* check if one of the packages in the [preferred] list already satisfies
@@ -818,9 +818,9 @@ int _alpm_resolvedeps(alpm_handle_t *handle, alpm_list_t *localpkgs,
 			_alpm_log(handle, ALPM_LOG_DEBUG,
 					"pulling dependency %s (needed by %s)\n",
 					spkg->name, pkg->name);
-			_alpm_depmiss_free(miss);
+			alpm_depmiss_free(miss);
 		} else if(resolvedep(handle, missdep, (targ = alpm_list_add(NULL, handle->db_local)), rem, 0)) {
-			_alpm_depmiss_free(miss);
+			alpm_depmiss_free(miss);
 		} else {
 			handle->pm_errno = ALPM_ERR_UNSATISFIED_DEPS;
 			char *missdepstring = alpm_dep_compute_string(missdep);
diff --git a/lib/libalpm/deps.h b/lib/libalpm/deps.h
index 546521f..0d41d49 100644
--- a/lib/libalpm/deps.h
+++ b/lib/libalpm/deps.h
@@ -29,7 +29,6 @@
 
 void _alpm_dep_free(alpm_depend_t *dep);
 alpm_depend_t *_alpm_dep_dup(const alpm_depend_t *dep);
-void _alpm_depmiss_free(alpm_depmissing_t *miss);
 alpm_list_t *_alpm_sortbydeps(alpm_handle_t *handle,
 		alpm_list_t *targets, alpm_list_t *ignore, int reverse);
 int _alpm_recursedeps(alpm_db_t *db, alpm_list_t **targs, int include_explicit);
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 899952b..04831fa 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -116,7 +116,7 @@ static int remove_prepare_cascade(alpm_handle_t *handle, alpm_list_t *lp)
 						_("could not find %s in database -- skipping\n"), miss->target);
 			}
 		}
-		alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free);
+		alpm_list_free_inner(lp, (alpm_list_fn_free)alpm_depmiss_free);
 		alpm_list_free(lp);
 		lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(handle->db_local),
 				trans->remove, NULL, 1);
@@ -153,7 +153,7 @@ static void remove_prepare_keep_needed(alpm_handle_t *handle, alpm_list_t *lp)
 				_alpm_pkg_free(pkg);
 			}
 		}
-		alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free);
+		alpm_list_free_inner(lp, (alpm_list_fn_free)alpm_depmiss_free);
 		alpm_list_free(lp);
 		lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(handle->db_local),
 				trans->remove, NULL, 1);
@@ -232,7 +232,7 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data)
 				if(data) {
 					*data = lp;
 				} else {
-					alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free);
+					alpm_list_free_inner(lp, (alpm_list_fn_free)alpm_depmiss_free);
 					alpm_list_free(lp);
 				}
 				RET_ERR(handle, ALPM_ERR_UNSATISFIED_DEPS, -1);
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 8b8a6ad..1bedbd1 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -451,7 +451,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
 				   dependency-reordered list below */
 				handle->pm_errno = 0;
 				if(data) {
-					alpm_list_free_inner(*data, (alpm_list_fn_free)_alpm_depmiss_free);
+					alpm_list_free_inner(*data, (alpm_list_fn_free)alpm_depmiss_free);
 					alpm_list_free(*data);
 					*data = NULL;
 				}
@@ -521,7 +521,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
 						*data = alpm_list_add(*data, newconflict);
 					}
 				}
-				alpm_list_free_inner(deps, (alpm_list_fn_free)_alpm_conflict_free);
+				alpm_list_free_inner(deps, (alpm_list_fn_free)alpm_conflict_free);
 				alpm_list_free(deps);
 				_alpm_dep_free(dep1);
 				_alpm_dep_free(dep2);
@@ -539,7 +539,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
 			trans->unresolvable = alpm_list_add(trans->unresolvable, rsync);
 		}
 
-		alpm_list_free_inner(deps, (alpm_list_fn_free)_alpm_conflict_free);
+		alpm_list_free_inner(deps, (alpm_list_fn_free)alpm_conflict_free);
 		alpm_list_free(deps);
 		deps = NULL;
 
@@ -585,13 +585,13 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
 						*data = alpm_list_add(*data, newconflict);
 					}
 				}
-				alpm_list_free_inner(deps, (alpm_list_fn_free)_alpm_conflict_free);
+				alpm_list_free_inner(deps, (alpm_list_fn_free)alpm_conflict_free);
 				alpm_list_free(deps);
 				goto cleanup;
 			}
 		}
 		EVENT(handle, ALPM_EVENT_INTERCONFLICTS_DONE, NULL, NULL);
-		alpm_list_free_inner(deps, (alpm_list_fn_free)_alpm_conflict_free);
+		alpm_list_free_inner(deps, (alpm_list_fn_free)alpm_conflict_free);
 		alpm_list_free(deps);
 	}
 
@@ -621,7 +621,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
 			if(data) {
 				*data = deps;
 			} else {
-				alpm_list_free_inner(deps, (alpm_list_fn_free)_alpm_depmiss_free);
+				alpm_list_free_inner(deps, (alpm_list_fn_free)alpm_depmiss_free);
 				alpm_list_free(deps);
 			}
 			goto cleanup;
@@ -1267,7 +1267,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
 			if(data) {
 				*data = conflict;
 			} else {
-				alpm_list_free_inner(conflict, (alpm_list_fn_free)_alpm_fileconflict_free);
+				alpm_list_free_inner(conflict, (alpm_list_fn_free)alpm_fileconflict_free);
 				alpm_list_free(conflict);
 			}
 			RET_ERR(handle, ALPM_ERR_FILE_CONFLICTS, -1);
diff --git a/src/pacman/remove.c b/src/pacman/remove.c
index aefe454..368c2e8 100644
--- a/src/pacman/remove.c
+++ b/src/pacman/remove.c
@@ -121,12 +121,13 @@ int pacman_remove(alpm_list_t *targets)
 					char *depstring = alpm_dep_compute_string(miss->depend);
 					colon_printf(_("%s: requires %s\n"), miss->target, depstring);
 					free(depstring);
+					alpm_depmiss_free(miss);
 				}
 				break;
 			default:
 				break;
 		}
-		FREELIST(data);
+		alpm_list_free(data);
 		retval = 1;
 		goto cleanup;
 	}
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 5ed43ed..e1df860 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -763,8 +763,9 @@ int sync_prepare_execute(void)
 		switch(err) {
 			case ALPM_ERR_PKG_INVALID_ARCH:
 				for(i = data; i; i = alpm_list_next(i)) {
-					const char *pkg = i->data;
+					char *pkg = i->data;
 					colon_printf(_("package %s does not have a valid architecture\n"), pkg);
+					free(pkg);
 				}
 				break;
 			case ALPM_ERR_UNSATISFIED_DEPS:
@@ -773,6 +774,7 @@ int sync_prepare_execute(void)
 					char *depstring = alpm_dep_compute_string(miss->depend);
 					colon_printf(_("%s: requires %s\n"), miss->target, depstring);
 					free(depstring);
+					alpm_depmiss_free(miss);
 				}
 				break;
 			case ALPM_ERR_CONFLICTING_DEPS:
@@ -788,6 +790,7 @@ int sync_prepare_execute(void)
 								conflict->package1, conflict->package2, reason);
 						free(reason);
 					}
+					alpm_conflict_free(conflict);
 				}
 				break;
 			default:
@@ -847,6 +850,7 @@ int sync_prepare_execute(void)
 									conflict->target, conflict->file);
 							break;
 					}
+					alpm_fileconflict_free(conflict);
 				}
 				break;
 			case ALPM_ERR_PKG_INVALID:
@@ -854,8 +858,9 @@ int sync_prepare_execute(void)
 			case ALPM_ERR_PKG_INVALID_SIG:
 			case ALPM_ERR_DLT_INVALID:
 				for(i = data; i; i = alpm_list_next(i)) {
-					const char *filename = i->data;
+					char *filename = i->data;
 					printf(_("%s is invalid or corrupted\n"), filename);
+					free(filename);
 				}
 				break;
 			default:
@@ -869,9 +874,7 @@ int sync_prepare_execute(void)
 
 	/* Step 4: release transaction resources */
 cleanup:
-	if(data) {
-		FREELIST(data);
-	}
+	alpm_list_free(data);
 	if(trans_release() == -1) {
 		retval = 1;
 	}
-- 
1.8.5.2



More information about the pacman-dev mailing list