wiedehopf / readsb

ADS-B decoder swiss knife
Other
321 stars 70 forks source link

argp leaks #64

Closed Huusky closed 3 months ago

Huusky commented 3 months ago

When using the version / usage / help commands, configSetDefaults() is called before parseCommandLine(...). argp_parse(...) checks for the version / usage / help commands, prints the appropriate output, and then exits without cleaning up the defaults.

$ valgrind --track-origins=yes --show-leak-kinds=all --leak-check=full ./readsb --help
==185857== Memcheck, a memory error detector
==185857== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==185857== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==185857== Command: ./readsb --help
==185857==
.....
==185857== 
==185857== HEAP SUMMARY:
==185857==     in use at exit: 4,080 bytes in 16 blocks
==185857==   total heap usage: 18 allocs, 2 frees, 5,117 bytes allocated
==185857== 
==185857== 2 bytes in 1 blocks are still reachable in loss record 1 of 16
==185857==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==185857==    by 0x4B3F58E: strdup (strdup.c:42)
==185857==    by 0x110932: configSetDefaults (readsb.c:124)
==185857==    by 0x110932: main (readsb.c:2532)
==185857== 
==185857== 2 bytes in 1 blocks are still reachable in loss record 2 of 16
==185857==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==185857==    by 0x4B3F58E: strdup (strdup.c:42)
==185857==    by 0x110941: configSetDefaults (readsb.c:125)
==185857==    by 0x110941: main (readsb.c:2532)
==185857== 
==185857== 2 bytes in 1 blocks are still reachable in loss record 3 of 16
==185857==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==185857==    by 0x4B3F58E: strdup (strdup.c:42)
==185857==    by 0x110950: configSetDefaults (readsb.c:126)
==185857==    by 0x110950: main (readsb.c:2532)
==185857== 
==185857== 2 bytes in 1 blocks are still reachable in loss record 4 of 16
==185857==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==185857==    by 0x4B3F58E: strdup (strdup.c:42)
==185857==    by 0x11095F: configSetDefaults (readsb.c:127)
==185857==    by 0x11095F: main (readsb.c:2532)
==185857== 
==185857== 2 bytes in 1 blocks are still reachable in loss record 5 of 16
==185857==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==185857==    by 0x4B3F58E: strdup (strdup.c:42)
==185857==    by 0x11096E: configSetDefaults (readsb.c:128)
==185857==    by 0x11096E: main (readsb.c:2532)
==185857== 
==185857== 2 bytes in 1 blocks are still reachable in loss record 6 of 16
==185857==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==185857==    by 0x4B3F58E: strdup (strdup.c:42)
==185857==    by 0x11097D: configSetDefaults (readsb.c:129)
==185857==    by 0x11097D: main (readsb.c:2532)
==185857== 
==185857== 2 bytes in 1 blocks are still reachable in loss record 7 of 16
==185857==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==185857==    by 0x4B3F58E: strdup (strdup.c:42)
==185857==    by 0x11098C: configSetDefaults (readsb.c:130)
==185857==    by 0x11098C: main (readsb.c:2532)
==185857== 
==185857== 2 bytes in 1 blocks are still reachable in loss record 8 of 16
==185857==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==185857==    by 0x4B3F58E: strdup (strdup.c:42)
==185857==    by 0x11099B: configSetDefaults (readsb.c:131)
==185857==    by 0x11099B: main (readsb.c:2532)
==185857== 
==185857== 2 bytes in 1 blocks are still reachable in loss record 9 of 16
==185857==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==185857==    by 0x4B3F58E: strdup (strdup.c:42)
==185857==    by 0x1109C5: configSetDefaults (readsb.c:135)
==185857==    by 0x1109C5: main (readsb.c:2532)
==185857== 
==185857== 2 bytes in 1 blocks are still reachable in loss record 10 of 16
==185857==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==185857==    by 0x4B3F58E: strdup (strdup.c:42)
==185857==    by 0x1109DF: configSetDefaults (readsb.c:137)
==185857==    by 0x1109DF: main (readsb.c:2532)
==185857== 
==185857== 2 bytes in 1 blocks are still reachable in loss record 11 of 16
==185857==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==185857==    by 0x4B3F58E: strdup (strdup.c:42)
==185857==    by 0x1109EE: configSetDefaults (readsb.c:138)
==185857==    by 0x1109EE: main (readsb.c:2532)
==185857== 
==185857== 2 bytes in 1 blocks are still reachable in loss record 12 of 16
==185857==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==185857==    by 0x4B3F58E: strdup (strdup.c:42)
==185857==    by 0x1109FD: configSetDefaults (readsb.c:139)
==185857==    by 0x1109FD: main (readsb.c:2532)
==185857== 
==185857== 2 bytes in 1 blocks are still reachable in loss record 13 of 16
==185857==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==185857==    by 0x4B3F58E: strdup (strdup.c:42)
==185857==    by 0x110A1A: configSetDefaults (readsb.c:140)
==185857==    by 0x110A1A: main (readsb.c:2532)
==185857== 
==185857== 13 bytes in 1 blocks are still reachable in loss record 14 of 16
==185857==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==185857==    by 0x4B3F58E: strdup (strdup.c:42)
==185857==    by 0x14F41F: beastInitConfig (sdr_beast.c:45)
==185857==    by 0x14FC59: sdrInitConfig (sdr.c:126)
==185857==    by 0x110B8D: configSetDefaults (readsb.c:188)
==185857==    by 0x110B8D: main (readsb.c:2532)
==185857== 
==185857== 41 bytes in 1 blocks are still reachable in loss record 15 of 16
==185857==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==185857==    by 0x4B3F58E: strdup (strdup.c:42)
==185857==    by 0x110AB1: configSetDefaults (readsb.c:155)
==185857==    by 0x110AB1: main (readsb.c:2532)
==185857== 
==185857== 4,000 bytes in 1 blocks are still reachable in loss record 16 of 16
==185857==    at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==185857==    by 0x117615: argp_parse (argp.c:98)
==185857==    by 0x1170AA: parseCommandLine (readsb.c:2063)
==185857==    by 0x110D1C: main (readsb.c:2567)
==185857== 
==185857== LEAK SUMMARY:
==185857==    definitely lost: 0 bytes in 0 blocks
==185857==    indirectly lost: 0 bytes in 0 blocks
==185857==      possibly lost: 0 bytes in 0 blocks
==185857==    still reachable: 4,080 bytes in 16 blocks
==185857==         suppressed: 0 bytes in 0 blocks
==185857== 
==185857== For lists of detected and suppressed errors, rerun with: -s
==185857== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

The same issue occurs when an unrecognized arg is passed.

$ valgrind --track-origins=yes --show-leak-kinds=all --leak-check=full ./readsb --invalid-arg
==185822== Memcheck, a memory error detector
==185822== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==185822== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==185822== Command: ./readsb --invalid-arg
==185822== 
./readsb: unrecognized option '--invalid-arg'
Try `./readsb --help' or `./readsb --usage' for more information.
Error parsing the given command line parameters, check readsb --usage and readsb --help for valid parameters.
invoked by: ./readsb --invalid-arg
==185822== 
==185822== HEAP SUMMARY:
==185822==     in use at exit: 4,000 bytes in 1 blocks
==185822==   total heap usage: 17 allocs, 16 frees, 4,093 bytes allocated
==185822== 
==185822== 4,000 bytes in 1 blocks are definitely lost in loss record 1 of 1
==185822==    at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==185822==    by 0x117615: argp_parse (argp.c:98)
==185822==    by 0x1170AA: parseCommandLine (readsb.c:2063)
==185822==    by 0x110D1C: main (readsb.c:2567)
==185822== 
==185822== LEAK SUMMARY:
==185822==    definitely lost: 4,000 bytes in 1 blocks
==185822==    indirectly lost: 0 bytes in 0 blocks
==185822==      possibly lost: 0 bytes in 0 blocks
==185822==    still reachable: 0 bytes in 0 blocks
==185822==         suppressed: 0 bytes in 0 blocks
==185822== 
==185822== For lists of detected and suppressed errors, rerun with: -s
==185822== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
wiedehopf commented 3 months ago

Really of no consequence.