From: Bartosz Golaszewski Date: Thu, 23 Feb 2017 15:03:12 +0000 (+0100) Subject: tests: fix potential memory corruption X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=c65a66036bf30e5766d53ee52da82d6d589ccffe;p=qemu-gpiodev%2Flibgpiod.git tests: fix potential memory corruption Valgrind is complaining about invalid reads and writes from the two line test cases. The culprit is the order in which the cleanup functions are called. Declare the chip pointers above the line handles so that we don't free the resources associated with the chip before releasing the lines. Signed-off-by: Bartosz Golaszewski --- diff --git a/tests/unit/tests-line.c b/tests/unit/tests-line.c index ef0db62..411ba9f 100644 --- a/tests/unit/tests-line.c +++ b/tests/unit/tests-line.c @@ -12,9 +12,9 @@ static void line_request_output(void) { + GU_CLEANUP(gu_close_chip) struct gpiod_chip *chip = NULL; GU_CLEANUP(gu_release_line) struct gpiod_line *line_0 = NULL; GU_CLEANUP(gu_release_line) struct gpiod_line *line_1 = NULL; - GU_CLEANUP(gu_close_chip) struct gpiod_chip *chip = NULL; int status; chip = gpiod_chip_open(gu_chip_path(0)); @@ -39,8 +39,8 @@ GU_DEFINE_TEST(line_request_output, static void line_set_value(void) { - GU_CLEANUP(gu_release_line) struct gpiod_line *line = NULL; GU_CLEANUP(gu_close_chip) struct gpiod_chip *chip = NULL; + GU_CLEANUP(gu_release_line) struct gpiod_line *line = NULL; int status; chip = gpiod_chip_open(gu_chip_path(0));