From c65a66036bf30e5766d53ee52da82d6d589ccffe Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Thu, 23 Feb 2017 16:03:12 +0100 Subject: [PATCH] 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 --- tests/unit/tests-line.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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)); -- 2.30.2