summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2008-12-15 00:18:44 (EST)
committer ticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2008-12-15 00:18:44 (EST)
commitf7eccd4bb54039f94312a56b40599d7cb446951e (patch)
tree4dec467a1f7c7827dfdf306bf22944e51c7a7d3b
parent90299e3df5c5d5eb4ae2189b11e44ec83995ca62 (diff)
opkg: (leak fixing, day 2) lots and lots of memory leaks fixed
git-svn-id: http://opkg.googlecode.com/svn/trunk@115 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
-rw-r--r--libopkg/args.c6
-rw-r--r--libopkg/hash_table.c1
-rw-r--r--libopkg/opkg.c15
-rw-r--r--libopkg/opkg_conf.c3
-rw-r--r--libopkg/opkg_conf.h2
-rw-r--r--libopkg/opkg_download.c9
-rw-r--r--libopkg/opkg_install.c4
-rw-r--r--libopkg/opkg_remove.c2
-rw-r--r--libopkg/opkg_upgrade.c2
-rw-r--r--libopkg/pkg.c53
-rw-r--r--libopkg/pkg_hash.c2
-rw-r--r--libopkg/pkg_parse.c10
-rw-r--r--libopkg/pkg_vec.c2
-rw-r--r--tests/libopkg_test.c3
14 files changed, 82 insertions, 32 deletions
diff --git a/libopkg/args.c b/libopkg/args.c
index fa2f633..6143f11 100644
--- a/libopkg/args.c
+++ b/libopkg/args.c
@@ -83,6 +83,12 @@ int args_init(args_t *args)
void args_deinit(args_t *args)
{
+ free (args->offline_root);
+ free (args->offline_root_pre_script_cmd);
+ free (args->offline_root_post_script_cmd);
+
+ free (args->dest);
+ free (args->tmp_dir);
free(args->conf_file);
args->conf_file = NULL;
}
diff --git a/libopkg/hash_table.c b/libopkg/hash_table.c
index c0c0530..b03dd74 100644
--- a/libopkg/hash_table.c
+++ b/libopkg/hash_table.c
@@ -85,6 +85,7 @@ void hash_table_deinit(hash_table_t *hash)
/* free the reminaing entries */
for (i = 0; i < hash->n_entries; i++) {
hash_entry_t *hash_entry = (hash->entries + i);
+ free (hash_entry->key);
/* skip the first entry as this is part of the array */
hash_entry = hash_entry->next;
while (hash_entry)
diff --git a/libopkg/opkg.c b/libopkg/opkg.c
index 9b29e68..18115fb 100644
--- a/libopkg/opkg.c
+++ b/libopkg/opkg.c
@@ -175,6 +175,7 @@ opkg_package_free (opkg_package_t *p)
free (p->description);
free (p->tags);
free (p->url);
+ free (p->repository);
free (p);
}
@@ -202,6 +203,10 @@ opkg_free (opkg_t *opkg)
opkg_conf_deinit (opkg->conf);
args_deinit (opkg->args);
+ free (opkg->options);
+ free (opkg->args);
+ free (opkg->conf);
+ free (opkg);
}
int
@@ -359,7 +364,7 @@ int
opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
{
int err;
- char *package_id = NULL, *stripped_filename;
+ char *stripped_filename;
opkg_progress_data_t pdata;
pkg_t *old, *new;
pkg_vec_t *deps, *all;
@@ -470,9 +475,6 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call
pdata.action = OPKG_INSTALL;
progress (pdata, 75);
- if (!package_id)
- package_id = strdup (package_name);
-
/* unpack the package */
err = opkg_install_pkg(opkg->conf, new, 0);
@@ -658,6 +660,7 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
pkg_src_t *src;
int sources_list_count, sources_done;
opkg_progress_data_t pdata;
+ char *tmp_file_name = NULL;
opkg_assert (opkg != NULL);
@@ -723,7 +726,6 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
sprintf_alloc (&list_file_name, "%s/%s", lists_dir, src->name);
if (src->gzip)
{
- char *tmp_file_name;
FILE *in, *out;
struct _curl_cb_data cb_data;
@@ -758,6 +760,7 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
}
else
err = opkg_download (opkg->conf, url, list_file_name, NULL, NULL);
+ free (tmp_file_name);
if (err)
{
@@ -776,8 +779,6 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
sprintf_alloc (&url, "%s/%s", src->value, "Packages.sig");
/* create temporary file for it */
- char *tmp_file_name;
-
sprintf_alloc (&tmp_file_name, "%s/%s", tmp, "Packages.sig");
err = opkg_download (opkg->conf, url, tmp_file_name, NULL, NULL);
diff --git a/libopkg/opkg_conf.c b/libopkg/opkg_conf.c
index 2642033..75ca48b 100644
--- a/libopkg/opkg_conf.c
+++ b/libopkg/opkg_conf.c
@@ -330,6 +330,7 @@ void opkg_conf_deinit(opkg_conf_t *conf)
free(conf->tmp_dir); /*XXX*/
free(conf->lists_dir);
+ free(conf->pending_dir);
pkg_src_list_deinit(&conf->pkg_src_list);
pkg_dest_list_deinit(&conf->pkg_dest_list);
@@ -578,7 +579,7 @@ static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename,
opkg_message(conf, OPKG_NOTICE, "defaulting architecture %s priority to 10\n", name);
value = strdup("10");
}
- nv_pair_list_append(&conf->arch_list, strdup(name), strdup(value));
+ nv_pair_list_append(&conf->arch_list, name, value);
} else {
fprintf(stderr, "WARNING: Ignoring unknown configuration "
"parameter: %s %s %s\n", type, name, value);
diff --git a/libopkg/opkg_conf.h b/libopkg/opkg_conf.h
index fe29e00..566bf46 100644
--- a/libopkg/opkg_conf.h
+++ b/libopkg/opkg_conf.h
@@ -50,7 +50,7 @@ struct opkg_conf
char *tmp_dir;
char *lists_dir;
- const char *pending_dir;
+ char *pending_dir;
/* options */
int autoremove;
diff --git a/libopkg/opkg_download.c b/libopkg/opkg_download.c
index 1d882a1..7c64a5b 100644
--- a/libopkg/opkg_download.c
+++ b/libopkg/opkg_download.c
@@ -99,19 +99,26 @@ int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name
free (userpwd);
}
res = curl_easy_perform (curl);
- curl_easy_cleanup (curl);
fclose (file);
if (res)
{
long error_code;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &error_code);
opkg_message(conf, OPKG_ERROR, "Failed to download %s, error %d\n", src, error_code);
+ free(tmp_file_location);
+ free(src_basec);
+ curl_easy_cleanup (curl);
return res;
}
+ curl_easy_cleanup (curl);
}
else
+ {
+ free(tmp_file_location);
+ free(src_basec);
return -1;
+ }
err = file_move(tmp_file_location, dest_file_name);
diff --git a/libopkg/opkg_install.c b/libopkg/opkg_install.c
index 6c1822c..f6666b2 100644
--- a/libopkg/opkg_install.c
+++ b/libopkg/opkg_install.c
@@ -394,6 +394,7 @@ int satisfy_dependencies_for(opkg_conf_t *conf, pkg_t *pkg)
}
if (ndepends <= 0) {
+ pkg_vec_free(depends);
return 0;
}
@@ -966,7 +967,7 @@ int opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
signal(SIGINT, old_handler);
else
sigprocmask(SIG_UNBLOCK, &newset, &oldset);
-
+ pkg_vec_free (replacees);
return 0;
@@ -996,6 +997,7 @@ int opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade)
else
sigprocmask(SIG_UNBLOCK, &newset, &oldset);
+ pkg_vec_free (replacees);
return err;
}
opkg_set_current_state (conf, OPKG_STATE_NONE, NULL);
diff --git a/libopkg/opkg_remove.c b/libopkg/opkg_remove.c
index 9288afc..c8cfb55 100644
--- a/libopkg/opkg_remove.c
+++ b/libopkg/opkg_remove.c
@@ -271,6 +271,8 @@ int opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg,int message)
free(dependents);
if (err) return err;
}
+ if (dependents)
+ free(dependents);
}
if ( message==0 ){
diff --git a/libopkg/opkg_upgrade.c b/libopkg/opkg_upgrade.c
index aa770f6..e002c37 100644
--- a/libopkg/opkg_upgrade.c
+++ b/libopkg/opkg_upgrade.c
@@ -72,6 +72,8 @@ int opkg_upgrade_pkg(opkg_conf_t *conf, pkg_t *old)
old->state_want = SW_DEINSTALL;
}
+ free(old_version);
+ free(new_version);
new->state_flag |= SF_USER;
return opkg_install_pkg(conf, new,1);
}
diff --git a/libopkg/pkg.c b/libopkg/pkg.c
index d9bae89..6793c82 100644
--- a/libopkg/pkg.c
+++ b/libopkg/pkg.c
@@ -142,6 +142,19 @@ int pkg_init(pkg_t *pkg)
return 0;
}
+void compound_depend_deinit (compound_depend_t *depends)
+{
+ int i;
+ for (i = 0; i < depends->possibility_count; i++)
+ {
+ depend_t *d;
+ d = depends->possibilities[i];
+ free (d->version);
+ free (d);
+ }
+ free (depends->possibilities);
+}
+
void pkg_deinit(pkg_t *pkg)
{
int i;
@@ -171,35 +184,39 @@ void pkg_deinit(pkg_t *pkg)
pkg->state_flag = SF_OK;
pkg->state_status = SS_NOT_INSTALLED;
+ //for (i = 0; i < pkg->replaces_count; i++)
+ free (pkg->replaces);
+ pkg->replaces = NULL;
+
for (i = 0; i < pkg->depends_count; i++)
free (pkg->depends_str[i]);
free(pkg->depends_str);
pkg->depends_str = NULL;
- pkg->depends_count = 0;
for (i = 0; i < pkg->provides_count; i++)
free (pkg->provides_str[i]);
free(pkg->provides_str);
pkg->provides_str = NULL;
- pkg->provides_count = 0;
for (i = 0; i < pkg->conflicts_count; i++)
free (pkg->conflicts_str[i]);
free(pkg->conflicts_str);
pkg->conflicts_str = NULL;
- pkg->conflicts_count = 0;
for (i = 0; i < pkg->replaces_count; i++)
free (pkg->replaces_str[i]);
free(pkg->replaces_str);
pkg->replaces_str = NULL;
- pkg->replaces_count = 0;
for (i = 0; i < pkg->recommends_count; i++)
free (pkg->recommends_str[i]);
free(pkg->recommends_str);
pkg->recommends_str = NULL;
- pkg->recommends_count = 0;
+
+ for (i = 0; i < pkg->suggests_count; i++)
+ free (pkg->suggests_str[i]);
+ free(pkg->suggests_str);
+ pkg->suggests_str = NULL;
if (pkg->depends)
{
@@ -207,23 +224,19 @@ void pkg_deinit(pkg_t *pkg)
int x;
for (x = 0; x < count; x++)
- {
- compound_depend_t *depends;
- depends = &pkg->depends[x];
-
- for (i = 0; i < depends->possibility_count; i++)
- {
- depend_t *d;
- d = depends->possibilities[i];
- free (d->version);
- free (d);
- }
- free (depends->possibilities);
- }
+ compound_depend_deinit (&pkg->depends[x]);
free (pkg->depends);
}
+
+ if (pkg->conflicts)
+ {
+ int x;
+ for (x = 0; x < pkg->conflicts_count; x++)
+ compound_depend_deinit (&pkg->conflicts[x]);
+ free (pkg->conflicts);
+ }
+
free (pkg->provides);
- free (pkg->conflicts);
pkg->pre_depends_count = 0;
free(pkg->pre_depends_str);
@@ -1398,6 +1411,7 @@ int pkg_free_installed_files(pkg_t *pkg)
}
str_list_deinit(pkg->installed_files);
+ free (pkg->installed_files);
}
pkg->installed_files = NULL;
@@ -1800,5 +1814,6 @@ int pkg_write_changed_filelists(opkg_conf_t *conf)
opkg_message(conf, OPKG_NOTICE, "pkg_write_filelist pkg=%s returned %d\n", pkg->name, err);
}
}
+ pkg_vec_free (installed_pkgs);
return 0;
}
diff --git a/libopkg/pkg_hash.c b/libopkg/pkg_hash.c
index 580fe6e..f38c6ca 100644
--- a/libopkg/pkg_hash.c
+++ b/libopkg/pkg_hash.c
@@ -73,7 +73,9 @@ void free_pkgs (const char *key, void *entry, void *data)
}
abstract_pkg_vec_free (ab_pkg->provided_by);
+ abstract_pkg_vec_free (ab_pkg->replaced_by);
pkg_vec_free (ab_pkg->pkgs);
+ free (ab_pkg->depended_upon_by);
free (ab_pkg->name);
free (ab_pkg);
}
diff --git a/libopkg/pkg_parse.c b/libopkg/pkg_parse.c
index cd0c6dc..cf3a882 100644
--- a/libopkg/pkg_parse.c
+++ b/libopkg/pkg_parse.c
@@ -140,12 +140,15 @@ int parseVersion(pkg_t *pkg, char *raw)
pkg->revision = "";
pkg->familiar_revision = "";
+ if (!pkg->version)
+ {
pkg->version= malloc(strlen(raw)+1);
if ( pkg->version == NULL ) {
fprintf(stderr, "%s: out of memory \n", __FUNCTION__);
return ENOMEM;
}
strcpy(pkg->version, raw);
+ }
hyphen= strrchr(pkg->version,'-');
@@ -304,6 +307,7 @@ int pkg_parse_raw(pkg_t *pkg, char ***raw, pkg_src_t *src, pkg_dest_t *dest)
else if(isGenericFieldType("Installed-Time:", *lines)) {
char *time_str = parseGenericFieldType("Installed-Time", *lines);
pkg->installed_time = strtoul(time_str, NULL, 0);
+ free (time_str);
}
break;
@@ -376,7 +380,11 @@ out:;
*raw = lines;
/* If the ipk has not a Provides line, we insert our false line */
if ( pkg_false_provides==1)
- pkg->provides_str = parseDependsString ((char *)"Provides: opkg_internal_use_only ", &pkg->provides_count);
+ {
+ pkg->provides_count = 1;
+ pkg->provides_str = malloc (sizeof (char*));
+ pkg->provides_str[0] = strdup ("opkg_internal_use_only");
+ }
if (pkg->name) {
return 0;
diff --git a/libopkg/pkg_vec.c b/libopkg/pkg_vec.c
index 72f9d7d..7d42a29 100644
--- a/libopkg/pkg_vec.c
+++ b/libopkg/pkg_vec.c
@@ -185,6 +185,8 @@ abstract_pkg_vec_t * abstract_pkg_vec_alloc(void)
void abstract_pkg_vec_free(abstract_pkg_vec_t *vec)
{
+ if (!vec)
+ return;
free(vec->pkgs);
free(vec);
}
diff --git a/tests/libopkg_test.c b/tests/libopkg_test.c
index 6288bd4..cab09b4 100644
--- a/tests/libopkg_test.c
+++ b/tests/libopkg_test.c
@@ -38,6 +38,7 @@ void
package_list_upgradable_callback (opkg_t *opkg, opkg_package_t *pkg, void *data)
{
printf ("%s - %s\n", pkg->name, pkg->version);
+ opkg_package_free (pkg);
}
void
@@ -91,11 +92,11 @@ main (int argc, char **argv)
if (pkg)
{
print_package (pkg);
- opkg_package_free (find_pkg);
opkg_package_free (pkg);
}
else
printf ("Package \"%s\" not found!\n", find_pkg->name);
+ opkg_package_free (find_pkg);
}
else
printf ("No package available to test find_package.\n");