From d4fa8ea77c8a2817a2a0d8be7940c3603169e5a6 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 12 Apr 2019 21:22:08 +0200 Subject: Fix memory leak in set_error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- set_error.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/set_error.c b/set_error.c index 5ee54ce..fa65141 100644 --- a/set_error.c +++ b/set_error.c @@ -5,13 +5,19 @@ void liberror_set_error(const char description[256], const char source[64], const char code_group[64], long long int code) { - struct liberror_error *cause; + struct liberror_error *cause = NULL, *old; struct liberror_error *error; - int have_cause; + int have_cause = 0, saved_errno; - cause = liberror_get_error(); - have_cause = !!cause; - cause = liberror_copy_error(cause); + old = liberror_get_error(); + if (old) { + have_cause = 1; + saved_errno = errno; + cause = malloc(sizeof(*cause)); + errno = saved_errno; + if (cause) + memcpy(cause, old, sizeof(*cause)); + } error = &liberror_error_; liberror_have_error_ = 1; -- cgit v1.2.3-70-g09d2