If no GPIO chips are present in the system, we bail out from
gpiod_chip_iter_new() before allocating the chips array. Add a check
in gpiod_chip_iter_free() to avoid calling free() for iter->chips in
that case.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
iter->num_chips = num_chips;
iter->offset = 0;
- if (num_chips == 0)
+ if (num_chips == 0) {
+ iter->chips = NULL;
return iter;
+ }
iter->chips = calloc(num_chips, sizeof(*iter->chips));
if (!iter->chips)
gpiod_chip_close(iter->chips[i]);
}
- free(iter->chips);
+ if (iter->chips)
+ free(iter->chips);
+
free(iter);
}