Skip to content

Fix a memory leak in local_soa() on FreeBSD - #110

Merged
evverx merged 1 commit into
avahi:masterfrom
evverx:local-soa-memory-leak
Nov 28, 2025
Merged

Fix a memory leak in local_soa() on FreeBSD#110
evverx merged 1 commit into
avahi:masterfrom
evverx:local-soa-memory-leak

Conversation

@evverx

@evverx evverx commented Nov 28, 2025

Copy link
Copy Markdown
Collaborator

by calling res_ndestroy() to free memory allocated by res_ninit().

Unless the unicats SOA heuristic is turned off explicitly with mdns.allow as described in
https://github.com/avahi/nss-mdns?tab=readme-ov-file#etcmdnsallow nss-mdns without this patch leaks memory every time forward lookups are performed with gethostbyname() (with the default documented configuration where mdns* comes after files and before dns in nsswitch.conf).

local_soa() has been using res_nclose instead of res_ndestroy since it was introduced in 8dd7984 but the FreeBSD support was removed in 1bd4895 and then brought back in fdd3293 so probably only the versions containing
fdd3293 like 0.15 and 0.15.1 are affected.

Fixes

==49966== 904 bytes in 1 blocks are definitely lost in loss record 9 of 12
==49966==    at 0x4856304: malloc (vg_replace_malloc.c:451)
==49966==    by 0x49742DE: __res_vinit (in /lib/libc.so.7)
==49966==    by 0x4B6BFF9: local_soa (util.c:134)
==49966==    by 0x4B6BDC1: verify_name_allowed_with_soa (util.c:69)
==49966==    by 0x4B6CBE0: _nss_mdns_gethostbyname_impl (nss.c:122)
==49966==    by 0x4B6CDF5: _nss_mdns_minimal_gethostbyname3_r (nss.c:201)
==49966==    by 0x4B6CEBB: _nss_mdns_minimal_gethostbyname2_r (nss.c:215)
==49966==    by 0x4B6DCF1: __nss_bsdcompat_gethostbyname2_r (bsdnss.c:265)
==49966==    by 0x49540CC: nsdispatch (in /lib/libc.so.7)
==49966==    by 0x49484CF: ??? (in /lib/libc.so.7)
==49966==    by 0x49481E0: gethostbyname_r (in /lib/libc.so.7)
==49966==    by 0x4948F04: gethostbyname (in /lib/libc.so.7)
==49966==

Closes #105

by calling res_ndestroy() to free memory allocated by res_ninit().

Unless the unicats SOA heuristic is turned off explicitly with `mdns.allow` as
described in
https://github.com/avahi/nss-mdns?tab=readme-ov-file#etcmdnsallow
nss-mdns without this patch leaks memory every time forward lookups are
performed with gethostbyname() (with the default documented configuration where
`mdns*` comes after `files` and before `dns` in `nsswitch.conf`).

local_soa() has been using `res_nclose` instead of `res_ndestroy` since
it was introduced in 8dd7984 but the
FreeBSD support was removed in 1bd4895
and then brought back in fdd3293 so
probably only the versions containing
fdd3293 like 0.15 and 0.15.1 are
affected.

Fixes
```
==49966== 904 bytes in 1 blocks are definitely lost in loss record 9 of 12
==49966==    at 0x4856304: malloc (vg_replace_malloc.c:451)
==49966==    by 0x49742DE: __res_vinit (in /lib/libc.so.7)
==49966==    by 0x4B6BFF9: local_soa (util.c:134)
==49966==    by 0x4B6BDC1: verify_name_allowed_with_soa (util.c:69)
==49966==    by 0x4B6CBE0: _nss_mdns_gethostbyname_impl (nss.c:122)
==49966==    by 0x4B6CDF5: _nss_mdns_minimal_gethostbyname3_r (nss.c:201)
==49966==    by 0x4B6CEBB: _nss_mdns_minimal_gethostbyname2_r (nss.c:215)
==49966==    by 0x4B6DCF1: __nss_bsdcompat_gethostbyname2_r (bsdnss.c:265)
==49966==    by 0x49540CC: nsdispatch (in /lib/libc.so.7)
==49966==    by 0x49484CF: ??? (in /lib/libc.so.7)
==49966==    by 0x49481E0: gethostbyname_r (in /lib/libc.so.7)
==49966==    by 0x4948F04: gethostbyname (in /lib/libc.so.7)
==49966==
```
Closes avahi#105
@evverx

evverx commented Nov 28, 2025

Copy link
Copy Markdown
Collaborator Author

https://github.com/evverx/avahi/actions/runs/19760939741/job/56622496914?pr=3 is green so I'll go ahead and merge it.

@evverx
evverx merged commit 5a04c7a into avahi:master Nov 28, 2025
22 checks passed
evverx added a commit to avahi/avahi that referenced this pull request Nov 28, 2025
Now that avahi/nss-mdns#110 is merged the test
can be run under Valgrind on FreeBSD as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nss-test fails under Valgrind on FreeBSD

1 participant