diff options
author | Mattias Andrée <maandree@kth.se> | 2019-04-12 22:32:26 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2019-04-12 22:32:26 +0200 |
commit | 5012504d2f215002a429b14f238ebfc1d0029c05 (patch) | |
tree | 7d70dbbdef6c93da503683c30b6c6d2e90f36881 /free_error.c | |
parent | Add readme (diff) | |
download | liberror-5012504d2f215002a429b14f238ebfc1d0029c05.tar.gz liberror-5012504d2f215002a429b14f238ebfc1d0029c05.tar.bz2 liberror-5012504d2f215002a429b14f238ebfc1d0029c05.tar.xz |
Add support for extended details
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'free_error.c')
-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); + } } |