summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-01-06 20:30:22 +0200
committerTimo Teras <timo.teras@iki.fi>2009-01-06 21:23:26 +0200
commit0314104d93b831f53a9ab21622ba61aa49b7cccd (patch)
tree765232ec3cd7a150cf3af46b425f43fdaf83dfc8
parent5e2aca267883a03dae8193eda9328a48b187fe84 (diff)
downloadapk-tools-0314104d93b831f53a9ab21622ba61aa49b7cccd.tar.gz
apk-tools-0314104d93b831f53a9ab21622ba61aa49b7cccd.tar.bz2
apk-tools-0314104d93b831f53a9ab21622ba61aa49b7cccd.tar.xz
apk-tools-0314104d93b831f53a9ab21622ba61aa49b7cccd.zip
db, pkg: fix rest of memory leaks
-rw-r--r--src/database.c35
-rw-r--r--src/hash.c2
-rw-r--r--src/package.c2
3 files changed, 38 insertions, 1 deletions
diff --git a/src/database.c b/src/database.c
index d1f86d0..8d8d563 100644
--- a/src/database.c
+++ b/src/database.c
@@ -102,6 +102,7 @@ struct apk_name *apk_db_get_name(struct apk_database *db, apk_blob_t name)
void apk_name_free(struct apk_name *name)
{
free(name->name);
+ free(name->pkgs);
free(name);
}
@@ -197,6 +198,13 @@ static void apk_db_diri_create(struct apk_db_dir_instance *diri)
}
}
+static void apk_db_diri_free(struct apk_database *db,
+ struct apk_db_dir_instance *diri)
+{
+ apk_db_dir_put(db, diri->dir);
+ free(diri);
+}
+
static struct apk_db_file *apk_db_file_new(struct apk_db_dir *dir,
apk_blob_t name,
struct hlist_node **after)
@@ -249,6 +257,11 @@ static struct apk_db_file *apk_db_file_get(struct apk_database *db,
return file;
}
+static void apk_db_file_free(struct apk_db_file *file)
+{
+ free(file);
+}
+
static struct apk_package *apk_db_pkg_add(struct apk_database *db, struct apk_package *pkg)
{
struct apk_package *idb;
@@ -623,6 +636,28 @@ static int apk_db_write_config(struct apk_database *db)
void apk_db_close(struct apk_database *db)
{
+ struct apk_package *pkg;
+ struct apk_db_dir_instance *diri;
+ struct apk_db_file *file;
+ struct hlist_node *dc, *dn, *fc, *fn;
+ int i;
+
+ list_for_each_entry(pkg, &db->installed.packages, installed_pkgs_list) {
+ hlist_for_each_entry_safe(diri, dc, dn, &pkg->owned_dirs, pkg_dirs_list) {
+ hlist_for_each_entry_safe(file, fc, fn, &diri->owned_files, diri_files_list)
+ apk_db_file_free(file);
+ apk_db_diri_free(db, diri);
+ }
+ }
+
+
+ for (i = 0; i < db->num_repos; i++)
+ free(db->repos[i].url);
+ for (i = 0; i < db->protected_paths->num; i++)
+ free(db->protected_paths->item[i]);
+ free(db->protected_paths);
+ free(db->world);
+
apk_hash_free(&db->available.names);
apk_hash_free(&db->available.packages);
apk_hash_free(&db->installed.dirs);
diff --git a/src/hash.c b/src/hash.c
index b4bbc90..9260b9b 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -35,7 +35,7 @@ int apk_hash_foreach(struct apk_hash *h, apk_hash_enumerator_f e, void *ctx)
for (i = 0; i < h->buckets->num; i++) {
hlist_for_each_safe(pos, n, &h->buckets->item[i]) {
r = e(((void *) pos) - offset, ctx);
- if (r != 0)
+ if (r != 0 && ctx != NULL)
return r;
}
}
diff --git a/src/package.c b/src/package.c
index 8a87b14..875c001 100644
--- a/src/package.c
+++ b/src/package.c
@@ -380,6 +380,8 @@ void apk_pkg_free(struct apk_package *pkg)
hlist_for_each_entry_safe(script, c, n, &pkg->scripts, script_list)
free(script);
+ if (pkg->depends)
+ free(pkg->depends);
if (pkg->version)
free(pkg->version);
if (pkg->url)