alpm: export *_free functions

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

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Andrew Gregory 2014-02-03 12:09:18 -05:00 committed by Allan McRae
parent 953808a9ee
commit b9601b1e59
9 changed files with 34 additions and 27 deletions

View File

@ -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_depmissing_free(alpm_depmissing_t *miss);
void alpm_conflict_free(alpm_conflict_t *conflict);
/* End of alpm_api */
/** @} */

View File

@ -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);

View File

@ -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 noet: */

View File

@ -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_depmissing_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_depmissing_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_depmissing_free(miss);
} else if(resolvedep(handle, missdep, (targ = alpm_list_add(NULL, handle->db_local)), rem, 0)) {
_alpm_depmiss_free(miss);
alpm_depmissing_free(miss);
} else {
handle->pm_errno = ALPM_ERR_UNSATISFIED_DEPS;
char *missdepstring = alpm_dep_compute_string(missdep);

View File

@ -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);

View File

@ -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_depmissing_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_depmissing_free);
alpm_list_free(lp);
lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(handle->db_local),
trans->remove, NULL, 1);
@ -232,7 +232,8 @@ 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_depmissing_free);
alpm_list_free(lp);
}
RET_ERR(handle, ALPM_ERR_UNSATISFIED_DEPS, -1);

View File

@ -451,7 +451,8 @@ 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_depmissing_free);
alpm_list_free(*data);
*data = NULL;
}
@ -527,7 +528,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);
@ -545,7 +546,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;
@ -591,13 +592,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);
}
@ -627,7 +628,8 @@ 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_depmissing_free);
alpm_list_free(deps);
}
goto cleanup;
@ -1273,7 +1275,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);

View File

@ -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_depmissing_free(miss);
}
break;
default:
break;
}
FREELIST(data);
alpm_list_free(data);
retval = 1;
goto cleanup;
}

View File

@ -764,8 +764,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:
@ -774,6 +775,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_depmissing_free(miss);
}
break;
case ALPM_ERR_CONFLICTING_DEPS:
@ -789,6 +791,7 @@ int sync_prepare_execute(void)
conflict->package1, conflict->package2, reason);
free(reason);
}
alpm_conflict_free(conflict);
}
break;
default:
@ -848,6 +851,7 @@ int sync_prepare_execute(void)
conflict->target, conflict->file);
break;
}
alpm_fileconflict_free(conflict);
}
break;
case ALPM_ERR_PKG_INVALID:
@ -855,8 +859,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:
@ -870,9 +875,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;
}