diff options
Diffstat (limited to '')
-rw-r--r-- | free_error.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/free_error.c b/free_error.c index a15d36c..1af0104 100644 --- a/free_error.c +++ b/free_error.c @@ -5,11 +5,34 @@ void liberror_free_error(struct liberror_error *error) { - if (!error) - return; - if (error->backtrace && !--error->backtrace->refcount) - free(error->backtrace); - liberror_free_error(error->cause); - if (error->dynamically_allocated) - free(error); + struct liberror_error *tmp; + while (error) { + if (error->backtrace && !--error->backtrace->refcount) + free(error->backtrace); + + switch (error->details_type) { + case LIBERROR_DETAILS_USER: + if (error->details.user.data && error->details.user.free_data) + error->details.user.free_data(error->details.user.data); + break; + + case LIBERROR_DETAILS_ONE_FILE: + free(error->details.one_file.name); + break; + + case LIBERROR_DETAILS_TWO_FILES: + free(error->details.two_files.name1); + free(error->details.two_files.name2); + break; + + case LIBERROR_DETAILS_NONE: + default: + break; + } + + tmp = error; + error = error->cause; + if (tmp->dynamically_allocated) + free(tmp); + } } |