free(stmp);
str_list_append(src, repo_ptr);
+ free(repo_ptr);
repositories++;
}
while (repositories > 0)
file_name = (char *)iter->data;
if (file_is_dir(file_name)) {
- str_list_append(&installed_dirs, strdup(file_name));
+ str_list_append(&installed_dirs, file_name);
continue;
}
sprintf_alloc(&installed_file_name, "%s", file_name);
}
str_list_append(pkg->installed_files, installed_file_name);
+ free(installed_file_name);
free(line);
}
return 0;
if (pkg->installed_files) {
- str_list_deinit(pkg->installed_files);
+ str_list_purge(pkg->installed_files);
}
pkg->installed_files = NULL;
return EINVAL;
}
- /* XXX: QUESTION: Is there a way to do this directly with deb_extract now? */
fputs(buffer, stream);
free(buffer);
const char *prefix)
{
char *dir_with_prefix;
+ char *buffer = NULL;
sprintf_alloc(&dir_with_prefix, "%s/%s", dir, prefix);
- deb_extract(pkg->local_filename, stderr,
+ buffer = deb_extract(pkg->local_filename, stderr,
extract_control_tar_gz
| extract_all_to_fs| extract_preserve_date
| extract_unconditional,
free(dir_with_prefix);
- /* XXX: BUG: how do we know if deb_extract worked or not? This is
- a defect in the current deb_extract from what I can tell.
-
- Once this is fixed, audit all calls to deb_extract. */
+ if (buffer == NULL) {
+ return EINVAL;
+ }
+ free(buffer);
return 0;
}
int pkg_extract_data_files_to_dir(pkg_t *pkg, const char *dir)
{
- deb_extract(pkg->local_filename, stderr,
+ char *buffer = NULL;
+ buffer = deb_extract(pkg->local_filename, stderr,
extract_data_tar_gz
| extract_all_to_fs| extract_preserve_date
| extract_unconditional,
dir, NULL);
- /* BUG: How do we know if deb_extract worked or not? This is a
- defect in the current deb_extract from what I can tell. */
+ if (buffer == NULL) {
+ return EINVAL;
+ }
+ free(buffer);
return 0;
}
int pkg_extract_data_file_names_to_stream(pkg_t *pkg, FILE *file)
{
+ char *buffer = NULL;
/* XXX: DPKG_INCOMPATIBILITY: deb_extract will extract all of the
data file names with a '.' as the first character. I've taught
opkg how to cope with the presence or absence of the '.', but
If we wanted to, we could workaround the deb_extract behavior
right here, by writing to a tmpfile, then munging things as we
wrote to the actual stream. */
- deb_extract(pkg->local_filename, file,
+ buffer = deb_extract(pkg->local_filename, file,
extract_quiet | extract_data_tar_gz | extract_list,
NULL, NULL);
/* BUG: How do we know if deb_extract worked or not? This is a
defect in the current deb_extract from what I can tell. */
+ if (buffer == NULL) {
+ return EINVAL;
+ }
+ free(buffer);
return 0;
}
void str_list_elt_deinit(str_list_elt_t *elt)
{
+ if (elt->data)
+ free(elt->data);
void_list_elt_deinit((void_list_elt_t *) elt);
}
void str_list_deinit(str_list_t *list)
{
- void_list_deinit((void_list_t *) list);
+ str_list_elt_t *elt;
+ while (!void_list_empty(list)) {
+ elt = str_list_first(list);
+ if (!elt)
+ return;
+ list_del_init(&elt->node);
+ free(elt->data);
+ elt->data=NULL;
+ free(elt);
+ }
}
int str_list_append(str_list_t *list, char *data)
{
- return void_list_append((void_list_t *) list, data);
+ return void_list_append((void_list_t *) list, strdup(data));
}
int str_list_push(str_list_t *list, char *data)
{
- return void_list_push((void_list_t *) list, data);
+ return void_list_push((void_list_t *) list, strdup(data));
}
str_list_elt_t *str_list_pop(str_list_t *list)
return (str_list_elt_t *) void_list_pop((void_list_t *) list);
}
-str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter)
+void str_list_remove(str_list_t *list, str_list_elt_t **iter)
{
- return (str_list_elt_t *) void_list_remove((void_list_t *) list,
+ str_list_elt_t * elt = void_list_remove((void_list_t *) list,
(void_list_elt_t **) iter);
+
+ str_list_elt_deinit(elt);
}
-char *str_list_remove_elt(str_list_t *list, const char *target_str)
+void str_list_remove_elt(str_list_t *list, const char *target_str)
{
- return (char *)void_list_remove_elt((void_list_t *) list,
+ char *str = void_list_remove_elt((void_list_t *) list,
(void *)target_str,
(void_list_cmp_t)strcmp);
+ if (str)
+ free(str);
}
str_list_elt_t *str_list_first(str_list_t *list) {
void str_list_purge(str_list_t *list) {
- str_list_elt_t *elt;
- while (!void_list_empty(list)) {
- elt = str_list_first(list);
- if (!elt)
- return;
- list_del_init(&elt->node);
- free(elt->data);
- elt->data=NULL;
- free(elt);
- }
+ str_list_deinit(list);
+ free(list);
}
int str_list_append(str_list_t *list, char *data);
int str_list_push(str_list_t *list, char *data);
str_list_elt_t *str_list_pop(str_list_t *list);
-str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
-char *str_list_remove_elt(str_list_t *list, const char *target_str);
+void str_list_remove(str_list_t *list, str_list_elt_t **iter);
+void str_list_remove_elt(str_list_t *list, const char *target_str);
str_list_elt_t *str_list_first(str_list_t *list);
str_list_elt_t *str_list_prev(str_list_t *list, str_list_elt_t *node);