Arondight/sudodev

内存泄露

Closed this issue · 1 comments

没有插入外部设备, 执行 valgrind --leak-check=full --show-leak-kinds=all ./sudodev add
部分输出:

==7931== HEAP SUMMARY:
==7931==     in use at exit: 8,200 bytes in 2 blocks
==7931==   total heap usage: 106 allocs, 104 frees, 126,457 bytes allocated
==7931== 
==7931== 8 bytes in 1 blocks are still reachable in loss record 1 of 2
==7931==    at 0x4C29110: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==7931==    by 0x4017D5: add (sudodev.c:193)
==7931==    by 0x402739: attempt (sudodev.c:559)
==7931==    by 0x40283F: main (sudodev.c:604)
==7931== 
==7931== 8,192 bytes in 1 blocks are definitely lost in loss record 2 of 2
==7931==    at 0x4C29110: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==7931==    by 0x403103: devs (devs.c:243)
==7931==    by 0x40171E: add (sudodev.c:173)
==7931==    by 0x402739: attempt (sudodev.c:559)
==7931==    by 0x40283F: main (sudodev.c:604)
==7931== 
==7931== LEAK SUMMARY:
==7931==    definitely lost: 8,192 bytes in 1 blocks
==7931==    indirectly lost: 0 bytes in 0 blocks
==7931==      possibly lost: 0 bytes in 0 blocks
==7931==    still reachable: 8 bytes in 1 blocks
==7931==         suppressed: 0 bytes in 0 blocks
==7931== 
==7931== For counts of detected and suppressed errors, rerun with: -v
==7931== Use --track-origins=yes to see where uninitialised values come from
==7931== ERROR SUMMARY: 12 errors from 4 contexts (suppressed: 0 from 0)

sudodev.c中的add()函数中有一段代码

if (count < 1)
{
    say (mode, MSG_W, "No available device found\n");
    return 1;
} 

建议将return 1 改为 goto CLEAN

艾玛,我用这玩意儿一跑貌似还有不少小毛病(不过看起来好像并不影响实际使用),有空时候再用这个跑跑看看。