From a29f20ae8a9f45ad55c4aa64bd4f2a415608609f Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Thu, 23 Feb 2017 11:47:57 +0100 Subject: [PATCH] tests: fix a potential segfault We should only sort the mockup chip pointers after determining that all gpiochip device files have actually been created. Otherwise we might sort invalid memory since we don't create the mockup_chip structures for nonexistent devices. Signed-off-by: Bartosz Golaszewski --- tests/unit/gpiod-unit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/gpiod-unit.c b/tests/unit/gpiod-unit.c index 44dc763..51b5945 100644 --- a/tests/unit/gpiod-unit.c +++ b/tests/unit/gpiod-unit.c @@ -380,11 +380,11 @@ static void test_prepare(struct gu_chip_descr *descr) } } - qsort(ctx->chips, ctx->num_chips, sizeof(*ctx->chips), chipcmp); - if (descr->num_chips != current) die("number of requested and detected mockup gpiochips is not the same"); + qsort(ctx->chips, ctx->num_chips, sizeof(*ctx->chips), chipcmp); + closedir(dir); } -- 2.30.2