Skip to contentSkip to conversation

gpioinfo: Clean up scandir allocations

PATCH Applied Joel Stanley 2 participants 2 messages Feb 2, 2022 – Feb 18, 2022 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpioinfo: Clean up scandir allocations

==3017== 176 (80 direct, 96 indirect) bytes in 1 blocks are definitely lost in loss record 2 of 2

==3017==    at 0x483F6C7: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==3017==    by 0x491CE92: ??? (in /lib/libc.so.6)
==3017==    by 0x10AAAC: main (gpioinfo.c:215)

The entires must be freed, and then the array itself.

---
 tools/gpioinfo.c | 2 ++
 1 file changed, 2 insertions(+)
tools/gpioinfo.c +2 -0
index 3d8911176281..d50af45dbf35 100644
@@ -231,7 +231,9 @@ int main(int argc, char **argv)
 			list_lines(chip);
 
 			gpiod_chip_unref(chip);
+			free(entries[i]);
 		}
+		free(entries);
 	} else {
 		for (i = 0; i < argc; i++) {
 			chip = chip_open_lookup(argv[i]);
Signature · 1 line
2.34.1
#1 lore raw
Quoted 28 lines · Joel Stanley

==3017== 176 (80 direct, 96 indirect) bytes in 1 blocks are definitely lost in loss record 2 of 2

==3017==    at 0x483F6C7: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==3017==    by 0x491CE92: ??? (in /lib/libc.so.6)
==3017==    by 0x10AAAC: main (gpioinfo.c:215)

The entires must be freed, and then the array itself.

---
 tools/gpioinfo.c | 2 ++
 1 file changed, 2 insertions(+)
tools/gpioinfo.c +2 -1
index 3d8911176281..d50af45dbf35 100644
@@ -231,7 +231,9 @@ int main(int argc, char **argv)
                        list_lines(chip);
 
                        gpiod_chip_unref(chip);
+                       free(entries[i]);
                }
+               free(entries);
        } else {
                for (i = 0; i < argc; i++) {
                        chip = chip_open_lookup(argv[i]);
--
Quoted 2 lines

2.34.1

Applied, thanks!

Bart