aboutsummaryrefslogtreecommitdiffstats
path: root/set_error.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2019-04-12 21:22:08 +0200
committerMattias Andrée <maandree@kth.se>2019-04-12 21:22:08 +0200
commitd4fa8ea77c8a2817a2a0d8be7940c3603169e5a6 (patch)
treea3c622ea987e6637c9fe348a7dd344d943d40d0a /set_error.c
parentFirst commit (diff)
downloadliberror-d4fa8ea77c8a2817a2a0d8be7940c3603169e5a6.tar.gz
liberror-d4fa8ea77c8a2817a2a0d8be7940c3603169e5a6.tar.bz2
liberror-d4fa8ea77c8a2817a2a0d8be7940c3603169e5a6.tar.xz
Fix memory leak in set_error
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'set_error.c')
-rw-r--r--set_error.c16
1 files 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;