tests: fix a segfault in error path
authorBartosz Golaszewski <bgolaszewski@baylibre.com>
Tue, 30 Jul 2019 11:49:49 +0000 (13:49 +0200)
committerBartosz Golaszewski <bgolaszewski@baylibre.com>
Tue, 30 Jul 2019 11:49:49 +0000 (13:49 +0200)
We may all the atexit() cleanup func before the gpio_mockup context
is setup. This will result in a segfault so add an appropriate check.

Fixes: b8659e044d50 ("tests: use libgpiomockup")
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
tests/gpiod-test.c

index 82e23ea11dc63a83f693edb024cf78f186ff6e42..f75173c7ff0192261eceed068d10e9bde02c4b4d 100644 (file)
@@ -314,7 +314,8 @@ static void cleanup_func(void)
        if (globals.toolpath)
                free(globals.toolpath);
 
-       gpio_mockup_unref(globals.mockup);
+       if (globals.mockup)
+               gpio_mockup_unref(globals.mockup);
 }
 
 static void event_lock(void)