diff options
author | pixdamix <pixdamix@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358> | 2009-10-29 05:07:11 (EDT) |
---|---|---|
committer | pixdamix <pixdamix@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358> | 2009-10-29 05:07:11 (EDT) |
commit | bb61b4e2022bea1f8728d18dac18239ed6931826 (patch) | |
tree | 0df7ce48dc61847a15d2fa0b6d7d1c08fe8563f5 /libopkg | |
parent | 26e659c660b69b5ecdd1bd6f6bf85520211b810e (diff) |
Fix problems in error list
push_error_list() should allocate the sizeof(struct) not sizeof(pointer
to struct).
And add some memory deallocation in error paths found while looking at
this.
git-svn-id: http://opkg.googlecode.com/svn/trunk@227 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
Diffstat (limited to 'libopkg')
-rw-r--r-- | libopkg/libopkg.c | 3 | ||||
-rw-r--r-- | libopkg/opkg_cmd.c | 17 | ||||
-rw-r--r-- | libopkg/opkg_utils.c | 26 | ||||
-rw-r--r-- | libopkg/opkg_utils.h | 2 |
4 files changed, 33 insertions, 15 deletions
diff --git a/libopkg/libopkg.c b/libopkg/libopkg.c index 552ee20..418a324 100644 --- a/libopkg/libopkg.c +++ b/libopkg/libopkg.c @@ -128,14 +128,13 @@ opkg_op (int argc, char *argv[]) err = opkg_conf_init (&opkg_conf, &args); + args_deinit (&args); if (err) { opkg_print_error_list (&opkg_conf); return err; } - args_deinit (&args); - if ( strcmp(cmd_name, "files")==0) opkg_cb_list = default_opkg_files_callback; else diff --git a/libopkg/opkg_cmd.c b/libopkg/opkg_cmd.c index 4a0410c..91976ae 100644 --- a/libopkg/opkg_cmd.c +++ b/libopkg/opkg_cmd.c @@ -143,17 +143,20 @@ opkg_cmd_t *opkg_cmd_find(const char *name) void opkg_print_error_list (opkg_conf_t *conf) { - if ( error_list ) { - reverse_error_list(&error_list); + struct errlist *err = error_list; + + if (err) { + reverse_error_list(&err); printf ("Collected errors:\n"); /* Here we print the errors collected and free the list */ - while (error_list != NULL) { - printf (" * %s", error_list->errmsg); - error_list = error_list->next; + while (err != NULL) { + printf (" * %s", err->errmsg); + err = err->next; } - free_error_list(); + + free_error_list(&error_list); } } @@ -786,6 +789,8 @@ static int opkg_list_installed_cmd(opkg_conf_t *conf, int argc, char **argv) } } + pkg_vec_free(available); + return 0; } diff --git a/libopkg/opkg_utils.c b/libopkg/opkg_utils.c index fb27b40..f0ef051 100644 --- a/libopkg/opkg_utils.c +++ b/libopkg/opkg_utils.c @@ -146,12 +146,26 @@ int line_is_blank(const char *line) return 1; } +/* + * XXX: this function should not allocate memory as it may be called to + * print an error because we are out of memory. + */ void push_error_list(struct errlist ** errors, char * msg){ struct errlist *err_lst_tmp; + err_lst_tmp = calloc (1, sizeof (struct errlist) ); + if (err_lst_tmp == NULL) { + fprintf(stderr, "%s: calloc: %s\n", __FUNCTION__, strerror(errno)); + return; + } + + err_lst_tmp->errmsg = strdup(msg); + if (err_lst_tmp->errmsg == NULL) { + fprintf(stderr, "%s: strdup: %s\n", __FUNCTION__, strerror(errno)); + free(err_lst_tmp); + return; + } - err_lst_tmp = calloc (1, sizeof (err_lst_tmp) ); - err_lst_tmp->errmsg=strdup(msg) ; err_lst_tmp->next = *errors; *errors = err_lst_tmp; } @@ -173,16 +187,16 @@ void reverse_error_list(struct errlist **errors){ } -void free_error_list(){ +void free_error_list(struct errlist **errors){ struct errlist *err_tmp_lst; - err_tmp_lst = error_list; + err_tmp_lst = *errors; while (err_tmp_lst != NULL) { free(err_tmp_lst->errmsg); err_tmp_lst = error_list->next; - free(error_list); - error_list = err_tmp_lst; + free(*errors); + *errors = err_tmp_lst; } diff --git a/libopkg/opkg_utils.h b/libopkg/opkg_utils.h index 226c7d1..ed9215b 100644 --- a/libopkg/opkg_utils.h +++ b/libopkg/opkg_utils.h @@ -23,7 +23,7 @@ void push_error_list(struct errlist **errors,char * msg); void reverse_error_list(struct errlist **errors); -void free_error_list(); +void free_error_list(struct errlist **errors); long unsigned int get_available_blocks(char * filesystem); char **read_raw_pkgs_from_file(const char *file_name); |