aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Woodward2005-01-16 22:00:17 +0000
committerJason Woodward2005-01-16 22:00:17 +0000
commit8523d1c37edddcda27b96c77483c19e6469b89f0 (patch)
tree75f52ef40922eeab460101ba67f477dad3f193fe /src
parent2cf19ce8b3eb76c64aace7c97e961a5795145e23 (diff)
downloadslapt-get-8523d1c37edddcda27b96c77483c19e6469b89f0.tar.gz
added bool free_pkgs member to pkg_list struct so all pkg_lists are free'd uniformly using free_pkg_list, even if their pkg list is pointers to pkg objects in other lists
Diffstat (limited to 'src')
-rw-r--r--src/action.c21
-rw-r--r--src/common.h1
-rw-r--r--src/package.c12
-rw-r--r--src/package.h1
-rw-r--r--src/transaction.c58
5 files changed, 39 insertions, 54 deletions
diff --git a/src/action.c b/src/action.c
index 3206177..02f1c6f 100644
--- a/src/action.c
+++ b/src/action.c
@@ -224,10 +224,7 @@ void pkg_action_remove(const rc_config *global_config,const pkg_action_args_t *a
}
- /* don't free, list of pointers to other packages that will be freed later */
- /* free_pkg_list(deps); */
- free(deps->pkgs);
- free(deps);
+ free_pkg_list(deps);
add_remove_to_transaction(&tran,pkg);
@@ -290,12 +287,8 @@ void pkg_action_search(const char *pattern){
free(short_description);
}
- /* don't free, list of pointers to other packages that will be freed later */
- /* free_pkg_list(matches) */
- free(matches->pkgs);
- free(matches);
- free(imatches->pkgs);
- free(imatches);
+ free_pkg_list(matches);
+ free_pkg_list(imatches);
free_pkg_list(pkgs);
free_pkg_list(installed_pkgs);
@@ -469,10 +462,7 @@ void pkg_action_upgrade_all(const rc_config *global_config){
}
- /* don't free, list of pointers to other packages that will be freed later */
- /* free_pkg_list(matches); */
- free(matches->pkgs);
- free(matches);
+ free_pkg_list(matches);
/* remove obsolete packages if prompted to */
if( global_config->remove_obsolete == 1 ){
@@ -495,8 +485,7 @@ void pkg_action_upgrade_all(const rc_config *global_config){
add_remove_to_transaction(&tran,deps->pkgs[c]);
}
}
- free(deps->pkgs);
- free(deps);
+ free_pkg_list(deps);
if( is_excluded(global_config,installed_pkgs->pkgs[r]) != 1 )
add_remove_to_transaction(&tran,installed_pkgs->pkgs[r]);
}
diff --git a/src/common.h b/src/common.h
index 98bbd9a..d8edcbb 100644
--- a/src/common.h
+++ b/src/common.h
@@ -20,6 +20,7 @@
#define MAX_REGEX_PARTS 10
#define SLACK_BASE_SET_REGEX "^./slackware/a$"
+typedef enum { FALSE = 0, TRUE } bool;
typedef struct {
regex_t regex;
diff --git a/src/package.c b/src/package.c
index 3f03101..16d9cd9 100644
--- a/src/package.c
+++ b/src/package.c
@@ -423,6 +423,7 @@ struct pkg_list *parse_packages_txt(FILE *pkg_list_fh){
free_regex(&size_c_regex);
free_regex(&size_u_regex);
+ list->free_pkgs = TRUE;
return list;
}
@@ -576,6 +577,7 @@ struct pkg_list *get_installed_pkgs(void){
free_regex(&compressed_size_reg);
free_regex(&uncompressed_size_reg);
+ list->free_pkgs = TRUE;
return list;
}
@@ -699,8 +701,10 @@ void free_pkg(pkg_info_t *pkg){
void free_pkg_list(struct pkg_list *list){
unsigned int i;
- for(i = 0;i < list->pkg_count;i++){
- free_pkg(list->pkgs[i]);
+ if( list->free_pkgs == TRUE ){
+ for(i = 0;i < list->pkg_count;i++){
+ free_pkg(list->pkgs[i]);
+ }
}
free(list->pkgs);
free(list);
@@ -1471,8 +1475,7 @@ static struct pkg_list *required_by(const rc_config *global_config,struct pkg_li
}
}
- free(required_of_required_by->pkgs);
- free(required_of_required_by);
+ free_pkg_list(required_of_required_by);
}
}
@@ -1810,6 +1813,7 @@ struct pkg_list *init_pkg_list(void){
list = slapt_malloc( sizeof *list );
list->pkgs = slapt_malloc( sizeof *list->pkgs );
list->pkg_count = 0;
+ list->free_pkgs = FALSE;
return list;
}
diff --git a/src/package.h b/src/package.h
index 3466b18..9364533 100644
--- a/src/package.h
+++ b/src/package.h
@@ -69,6 +69,7 @@ typedef struct {
struct pkg_list {
pkg_info_t **pkgs;
unsigned int pkg_count;
+ bool free_pkgs;
};
typedef struct {
diff --git a/src/transaction.c b/src/transaction.c
index cd33b88..50e9732 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -21,23 +21,18 @@ static void add_suggestion(transaction_t *tran, pkg_info_t *pkg);
void init_transaction(transaction_t *tran){
- tran->install_pkgs = slapt_malloc( sizeof *tran->install_pkgs );
- tran->remove_pkgs = slapt_malloc( sizeof *tran->remove_pkgs );
- tran->upgrade_pkgs = slapt_malloc( sizeof *tran->upgrade_pkgs );
- tran->exclude_pkgs = slapt_malloc( sizeof *tran->exclude_pkgs );
+ tran->install_pkgs = init_pkg_list();
+ tran->remove_pkgs = init_pkg_list();
+ tran->exclude_pkgs = init_pkg_list();
- tran->install_pkgs->pkgs = slapt_malloc( sizeof *tran->install_pkgs->pkgs );
- tran->remove_pkgs->pkgs = slapt_malloc( sizeof *tran->remove_pkgs->pkgs );
+ tran->upgrade_pkgs = slapt_malloc( sizeof *tran->upgrade_pkgs );
tran->upgrade_pkgs->pkgs = slapt_malloc( sizeof *tran->upgrade_pkgs->pkgs );
- tran->exclude_pkgs->pkgs = slapt_malloc( sizeof *tran->exclude_pkgs->pkgs );
+ tran->upgrade_pkgs->pkg_count = 0;
+
tran->suggests = slapt_malloc(sizeof *tran->suggests );
tran->suggests[0] = '\0';
- tran->install_pkgs->pkg_count = 0;
- tran->remove_pkgs->pkg_count = 0;
- tran->upgrade_pkgs->pkg_count = 0;
- tran->exclude_pkgs->pkg_count = 0;
}
int handle_transaction(const rc_config *global_config, transaction_t *tran){
@@ -247,15 +242,15 @@ void add_install_to_transaction(transaction_t *tran,pkg_info_t *pkg){
tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count] = slapt_malloc(
sizeof *tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count]
);
- memcpy(
+ tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count] = memcpy(
tran->install_pkgs->pkgs[tran->install_pkgs->pkg_count],
pkg,
sizeof *pkg
);
++tran->install_pkgs->pkg_count;
- }
- add_suggestion(tran,pkg);
+ add_suggestion(tran,pkg);
+ }
}
@@ -280,7 +275,7 @@ void add_remove_to_transaction(transaction_t *tran,pkg_info_t *pkg){
tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count] = slapt_malloc(
sizeof *tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count]
);
- memcpy(
+ tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count] = memcpy(
tran->remove_pkgs->pkgs[tran->remove_pkgs->pkg_count],
pkg,
sizeof *pkg
@@ -311,7 +306,7 @@ void add_exclude_to_transaction(transaction_t *tran,pkg_info_t *pkg){
tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count] = slapt_malloc(
sizeof *tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count]
);
- memcpy(
+ tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count] = memcpy(
tran->exclude_pkgs->pkgs[tran->exclude_pkgs->pkg_count],
pkg,
sizeof *pkg
@@ -351,12 +346,12 @@ void add_upgrade_to_transaction(
sizeof *tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade
);
- memcpy(
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed = memcpy(
tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->installed,
installed_pkg,
sizeof *installed_pkg
);
- memcpy(
+ tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade = memcpy(
tran->upgrade_pkgs->pkgs[tran->upgrade_pkgs->pkg_count]->upgrade,
upgrade_pkg,
sizeof *upgrade_pkg
@@ -401,14 +396,18 @@ void free_transaction(transaction_t *tran){
unsigned int i;
for(i = 0;i < tran->install_pkgs->pkg_count; i++){
+ /* no free_pkg() b/c the *pkg is all memcpy'd */
free(tran->install_pkgs->pkgs[i]);
}
free(tran->install_pkgs->pkgs);
+ free(tran->install_pkgs);
for(i = 0;i < tran->remove_pkgs->pkg_count; i++){
+ /* no free_pkg() b/c the *pkg is all memcpy'd */
free(tran->remove_pkgs->pkgs[i]);
}
free(tran->remove_pkgs->pkgs);
+ free(tran->remove_pkgs);
for(i = 0;i < tran->upgrade_pkgs->pkg_count; i++){
free(tran->upgrade_pkgs->pkgs[i]->upgrade);
@@ -416,15 +415,13 @@ void free_transaction(transaction_t *tran){
free(tran->upgrade_pkgs->pkgs[i]);
}
free(tran->upgrade_pkgs->pkgs);
+ free(tran->upgrade_pkgs);
for(i = 0; i < tran->exclude_pkgs->pkg_count;i++){
+ /* no free_pkg() b/c the *pkg is all memcpy'd */
free(tran->exclude_pkgs->pkgs[i]);
}
free(tran->exclude_pkgs->pkgs);
-
- free(tran->install_pkgs);
- free(tran->remove_pkgs);
- free(tran->upgrade_pkgs);
free(tran->exclude_pkgs);
free(tran->suggests);
@@ -500,9 +497,7 @@ int add_deps_to_trans(const rc_config *global_config, transaction_t *tran, struc
if( (dep_return == -1) && (global_config->ignore_dep == 0) ){
printf("Excluding %s, use --ignore-dep to override\n",pkg->name);
add_exclude_to_transaction(tran,pkg);
- /* free_pkg_list(deps); */
- free(deps->pkgs);
- free(deps);
+ free_pkg_list(deps);
return -1;
}
@@ -546,9 +541,7 @@ int add_deps_to_trans(const rc_config *global_config, transaction_t *tran, struc
}
- /* free_pkg_list(deps); */
- free(deps->pkgs);
- free(deps);
+ free_pkg_list(deps);
return 0;
}
@@ -569,21 +562,18 @@ pkg_info_t *is_conflicted(transaction_t *tran, struct pkg_list *avail_pkgs, stru
printf(_("%s, which is to be installed, conflicts with %s\n"),
conflicts->pkgs[i]->name,conflicts->pkgs[i]->version, pkg->name,pkg->version
);
- free(conflicts->pkgs);
- free(conflicts);
+ free_pkg_list(conflicts);
return c;
}
if(get_newest_pkg(installed_pkgs,conflicts->pkgs[i]->name) != NULL) {
pkg_info_t *c = conflicts->pkgs[i];
printf(_("Installed %s conflicts with %s\n"),conflicts->pkgs[i]->name,pkg->name);
- free(conflicts->pkgs);
- free(conflicts);
+ free_pkg_list(conflicts);
return c;
}
}
- free(conflicts->pkgs);
- free(conflicts);
+ free_pkg_list(conflicts);
return NULL;
}