From: Bartosz Golaszewski Date: Thu, 23 Feb 2017 10:47:57 +0000 (+0100) Subject: tests: fix a potential segfault X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=a29f20ae8a9f45ad55c4aa64bd4f2a415608609f;p=qemu-gpiodev%2Flibgpiod.git 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 --- 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); }