From 3d9501007a24bf5422335238960f6777d2684d35 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Mon, 23 Oct 2017 17:47:52 +0200 Subject: lib: Fix exit bug in dev.c If the library init() fails, the fini() call tries to access unreleased resources. The fix resets the ai struct to 0 if init() fails and checks a heap pointer for NULL before the fini() accesses internals. Signed-off-by: dimitri staessens Signed-off-by: Sander Vrijders --- src/lib/dev.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/dev.c b/src/lib/dev.c index 85dbfb0a..e216baab 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -713,6 +713,7 @@ __attribute__((constructor)) static void init(int argc, fail_fds: fprintf(stderr, "FATAL: ouroboros-dev init failed. " "Make sure an IRMd is running.\n\n"); + memset(&ai, 0, sizeof(ai)); exit(EXIT_FAILURE); } @@ -720,6 +721,9 @@ __attribute__((destructor)) static void fini(void) { int i = 0; + if (ai.fds == NULL) + return; + bmp_destroy(ai.fds); bmp_destroy(ai.fqueues); -- cgit v1.2.3