void hash_table_deinit(hash_table_t *hash)
{
- free(hash->entries);
+ int i;
+ if (!hash)
+ return;
+
+ /* free the reminaing entries */
+ for (i = 0; i < hash->n_entries; i++) {
+ hash_entry_t *hash_entry = (hash->entries + i);
+ /* skip the first entry as this is part of the array */
+ hash_entry = hash_entry->next;
+ while (hash_entry)
+ {
+ hash_entry_t *old = hash_entry;
+ hash_entry = hash_entry->next;
+ free (old->key);
+ free (old);
+ }
+ }
+
+ free (hash->entries);
+
hash->entries = NULL;
hash->n_entries = 0;
}
typedef struct hash_table hash_table_t;
struct hash_entry {
- const char * key;
+ char * key;
void * data;
struct hash_entry * next;
};
}
if (args->offline_root) {
- char *tmp = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
+ char *tmp;// = malloc(strlen(lists_dir) + strlen(args->offline_root) + 1);
sprintf_alloc(&tmp, "%s/%s",args->offline_root,lists_dir);
free(lists_dir);
lists_dir = tmp;
sprintf_alloc(&etc_opkg_conf_pattern, "%s/etc/opkg/*.conf", args->offline_root);
memset(&globbuf, 0, sizeof(globbuf));
err = glob(etc_opkg_conf_pattern, 0, NULL, &globbuf);
+ if (args->offline_root)
+ free (etc_opkg_conf_pattern);
if (!err) {
int i;
for (i = 0; i < globbuf.gl_pathc; i++) {
#endif /* OPKG_DEBUG_NO_TMP_CLEANUP */
free(conf->tmp_dir); /*XXX*/
+ free(conf->lists_dir);
pkg_src_list_deinit(&conf->pkg_src_list);
pkg_dest_list_deinit(&conf->pkg_dest_list);
pkg_dest_t *default_dest;
char *tmp_dir;
- const char *lists_dir;
+ char *lists_dir;
const char *pending_dir;
/* options */
void pkg_deinit(pkg_t *pkg)
{
+ int i;
+
free(pkg->name);
pkg->name = NULL;
pkg->epoch = 0;
pkg->state_want = SW_UNKNOWN;
pkg->state_flag = SF_OK;
pkg->state_status = SS_NOT_INSTALLED;
+
+ 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->depends_count = 0;
- /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->depends ? */
+ 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;
+
+ if (pkg->depends)
+ {
+ int count = pkg->pre_depends_count + pkg->depends_count + pkg->recommends_count + pkg->suggests_count;
+ 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);
+ }
+ free (pkg->depends);
+ }
+ free (pkg->provides);
+ free (pkg->conflicts);
+
pkg->pre_depends_count = 0;
free(pkg->pre_depends_str);
pkg->pre_depends_str = NULL;
pkg->provides_count = 0;
- /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->provides ? */
- /* XXX: CLEANUP: MEMORY_LEAK: how to free up pkg->suggests ? */
free(pkg->filename);
pkg->filename = NULL;
free(pkg->local_filename);
return hash_table_init(name, hash, len);
}
+void free_pkgs (const char *key, void *entry, void *data)
+{
+ int i;
+ abstract_pkg_t *ab_pkg;
+
+ /* each entry in the hash table is an abstract package, which contains a list
+ * of packages that provide the abstract package */
+
+ ab_pkg = (abstract_pkg_t*) entry;
+
+ if (ab_pkg->pkgs)
+ {
+ for (i = 0; i < ab_pkg->pkgs->len; i++)
+ {
+ pkg_deinit (ab_pkg->pkgs->pkgs[i]);
+ free (ab_pkg->pkgs->pkgs[i]);
+ }
+ }
+
+ abstract_pkg_vec_free (ab_pkg->provided_by);
+ pkg_vec_free (ab_pkg->pkgs);
+ free (ab_pkg->name);
+ free (ab_pkg);
+}
+
void pkg_hash_deinit(hash_table_t *hash)
{
+ hash_table_foreach (hash, free_pkgs, NULL);
hash_table_deinit(hash);
}
void pkg_vec_free(pkg_vec_t *vec)
{
- free(vec->pkgs);
+ if (!vec)
+ return;
+
+ if (vec->pkgs)
+ free(vec->pkgs);
+
free(vec);
}