From 5012504d2f215002a429b14f238ebfc1d0029c05 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 12 Apr 2019 22:32:26 +0200 Subject: Add support for extended details MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- free_error.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'free_error.c') 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); + } } -- cgit v1.2.3-70-g09d2