On Sunday, January 12, 2025 2:56:50 PM Pacific Standard Time Hal Murray wrote:
> James Browning said:
> > I would be more concerned in the near and intermediate terms about the
> > possibility of allocating memory to pointer that already have associated
> > memory.
> 
> Right.  But one way to find those is to fix the exit code to free
> everything so that anything left in use was a not-free-ed bug.  Then
> valgrind can tell you about them and you can investigate.  If the exit
> code doesn't free everything, you have to plow through all the legitimate
> leftovers.  I think that will take too long to be practical.
> 
> But we could iterate.  Each time we find a legitmate leftover, fix the
> exit code to free it (and friends), then try again.
> 
> The question is do we care enough about dangling blocks to fixup the
> free-on-exit code?
Probably, I think we need more developer hours per month to tackle it though.

```sh
$ sudo valgrind -s --leak-check=full -- ~/ntpsec/build/main/ntpd/ntpd -mnN
:::so much snipped:::
==260313== HEAP SUMMARY:
==260313==     in use at exit: 906,447 bytes in 12,877 blocks
==260313==   total heap usage: 50,137 allocs, 37,260 frees, 6,071,589 bytes 
allocated
:::snip:::
==260313== LEAK SUMMARY:
==260313==    definitely lost: 44 bytes in 6 blocks
==260313==    indirectly lost: 816 bytes in 4 blocks
==260313==      possibly lost: 57,900 bytes in 5 blocks
==260313==    still reachable: 847,687 bytes in 12,862 blocks
==260313==         suppressed: 0 bytes in 0 blocks
==260313== Reachable blocks (those to which a pointer was found) are not 
shown.
==260313== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==260313== 
==260313== ERROR SUMMARY: 8 errors from 8 contexts (suppressed: 0 from 0)
```

It looks like the offending lines include:
5x create_string_token (ntp_scanner.c:769)
1x ssl_init (ssl_init.c:97)
1x hack_restrict (ntp_restrict.c:555)
1x alloc_auth_info (authkeys.c:285)
1x newpeer (ntp_peer.c:599)
1x init_recvbuff (ntp_recvbuff.c:91)

NOTE: This does not exercise the time server, refclocks (other than SHM), MS-
SNTP, NTS, stats logging, mode 6, and so forth.

Attached is the valgrind session minus the largely irrelevant ntpd messages.
sudo valgrind -s --leak-check=full -- ~/ntpsec/build/main/ntpd/ntpd -mnN
[sudo] password for jamesb:
==260313== Memcheck, a memory error detector
==260313== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==260313== Using Valgrind-3.24.0 and LibVEX; rerun with -h for copyright info
==260313== Command: /home/jamesb/ntpsec/build/main/ntpd/ntpd -mnN
==260313==
:::so much snipped:::
==260313==
==260313== HEAP SUMMARY:
==260313==     in use at exit: 906,447 bytes in 12,877 blocks
==260313==   total heap usage: 50,137 allocs, 37,260 frees, 6,071,589 bytes allocated
==260313==
==260313== 10 bytes in 1 blocks are definitely lost in loss record 40 of 441
==260313==    at 0x488CABC: realloc (vg_replace_malloc.c:1801)
==260313==    by 0x153E63: ereallocz (emalloc.c:43)
==260313==    by 0x153F53: estrdup_impl (emalloc.c:131)
==260313==    by 0x13A57B: create_string_token (ntp_scanner.c:769)
==260313==    by 0x13B23F: yylex (ntp_scanner.c:979)
==260313==    by 0x13E1FF: yyparse (ntp_parser.tab.c:1679)
==260313==    by 0x130C9F: readconfig (ntp_config.c:3145)
==260313==    by 0x13DC6B: main (ntpd.c:848)
==260313==
==260313== 18 bytes in 4 blocks are definitely lost in loss record 72 of 441
==260313==    at 0x488CABC: realloc (vg_replace_malloc.c:1801)
==260313==    by 0x153E63: ereallocz (emalloc.c:43)
==260313==    by 0x153F53: estrdup_impl (emalloc.c:131)
==260313==    by 0x13A57B: create_string_token (ntp_scanner.c:769)
==260313==    by 0x13AD3B: yylex (ntp_scanner.c:1022)
==260313==    by 0x13E1FF: yyparse (ntp_parser.tab.c:1679)
==260313==    by 0x130C9F: readconfig (ntp_config.c:3145)
==260313==    by 0x13DC6B: main (ntpd.c:848)
==260313==
==260313== 832 (16 direct, 816 indirect) bytes in 1 blocks are definitely lost in loss record 345 of 441
==260313==    at 0x4885550: malloc (vg_replace_malloc.c:446)
==260313==    by 0x4A2DF83: CRYPTO_malloc (in /usr/lib64/libcrypto.so.3.2.2)
==260313==    by 0x4A0DC17: EVP_MAC_CTX_dup (in /usr/lib64/libcrypto.so.3.2.2)
==260313==    by 0x153977: ssl_init (ssl_init.c:97)
==260313==    by 0x13D187: main (ntpd.c:623)
==260313==
==260313== 988 bytes in 1 blocks are possibly lost in loss record 353 of 441
==260313==    at 0x488CABC: realloc (vg_replace_malloc.c:1801)
==260313==    by 0x153E63: ereallocz (emalloc.c:43)
==260313==    by 0x1473B7: alloc_res6 (ntp_restrict.c:207)
==260313==    by 0x1473B7: hack_restrict (ntp_restrict.c:550)
==260313==    by 0x12FBC3: config_access (ntp_config.c:1790)
==260313==    by 0x12FBC3: config_ntpd (ntp_config.c:3040)
==260313==    by 0x12FBC3: save_and_apply_config_tree (ntp_config.c:3212)
==260313==    by 0x130CE7: readconfig (ntp_config.c:3169)
==260313==    by 0x13DC6B: main (ntpd.c:848)
==260313==
==260313== 1,008 bytes in 1 blocks are possibly lost in loss record 362 of 441
==260313==    at 0x488CABC: realloc (vg_replace_malloc.c:1801)
==260313==    by 0x153E63: ereallocz (emalloc.c:43)
==260313==    by 0x147447: alloc_res4 (ntp_restrict.c:182)
==260313==    by 0x147447: hack_restrict (ntp_restrict.c:555)
==260313==    by 0x12FBC3: config_access (ntp_config.c:1790)
==260313==    by 0x12FBC3: config_ntpd (ntp_config.c:3040)
==260313==    by 0x12FBC3: save_and_apply_config_tree (ntp_config.c:3212)
==260313==    by 0x130CE7: readconfig (ntp_config.c:3169)
==260313==    by 0x13DC6B: main (ntpd.c:848)
==260313==
==260313== 1,152 bytes in 1 blocks are possibly lost in loss record 365 of 441
==260313==    at 0x488CABC: realloc (vg_replace_malloc.c:1801)
==260313==    by 0x153E63: ereallocz (emalloc.c:43)
==260313==    by 0x150453: auth_moremem (authkeys.c:185)
==260313==    by 0x150CA3: alloc_auth_info (authkeys.c:285)
==260313==    by 0x150D87: authtrust (authkeys.c:413)
==260313==    by 0x12F1D3: config_auth (ntp_config.c:1181)
==260313==    by 0x12F1D3: config_ntpd (ntp_config.c:3038)
==260313==    by 0x12F1D3: save_and_apply_config_tree (ntp_config.c:3212)
==260313==    by 0x130CE7: readconfig (ntp_config.c:3169)
==260313==    by 0x13DC6B: main (ntpd.c:848)
==260313==
==260313== 9,472 bytes in 1 blocks are possibly lost in loss record 425 of 441
==260313==    at 0x488CABC: realloc (vg_replace_malloc.c:1801)
==260313==    by 0x153E63: ereallocz (emalloc.c:43)
==260313==    by 0x1360CF: getmorepeermem (ntp_peer.c:116)
==260313==    by 0x1360CF: newpeer (ntp_peer.c:599)
==260313==    by 0x1397FB: dns_take_pool (ntp_proto.c:2508)
==260313==    by 0x13C4AB: dns_check (ntp_dns.c:132)
==260313==    by 0x13DF43: mainloop (ntpd.c:952)
==260313==    by 0x13DF43: main (ntpd.c:879)
==260313==
==260313== 45,280 bytes in 1 blocks are possibly lost in loss record 436 of 441
==260313==    at 0x488CABC: realloc (vg_replace_malloc.c:1801)
==260313==    by 0x153E63: ereallocz (emalloc.c:43)
==260313==    by 0x146CDF: create_buffers (ntp_recvbuff.c:61)
==260313==    by 0x146CDF: init_recvbuff (ntp_recvbuff.c:91)
==260313==    by 0x131B37: init_io (ntp_io.c:343)
==260313==    by 0x13D1C3: main (ntpd.c:635)
==260313==
==260313== LEAK SUMMARY:
==260313==    definitely lost: 44 bytes in 6 blocks
==260313==    indirectly lost: 816 bytes in 4 blocks
==260313==      possibly lost: 57,900 bytes in 5 blocks
==260313==    still reachable: 847,687 bytes in 12,862 blocks
==260313==         suppressed: 0 bytes in 0 blocks
==260313== Reachable blocks (those to which a pointer was found) are not shown.
==260313== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==260313==
==260313== ERROR SUMMARY: 8 errors from 8 contexts (suppressed: 0 from 0)
_______________________________________________
devel mailing list
devel@ntpsec.org
https://lists.ntpsec.org/mailman/listinfo/devel

Reply via email to