Fix a memory leak in local_soa() on FreeBSD - #110
Merged
Conversation
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
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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
by calling res_ndestroy() to free memory allocated by res_ninit().
Unless the unicats SOA heuristic is turned off explicitly with
mdns.allowas described inhttps://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 afterfilesand beforednsinnsswitch.conf).local_soa() has been using
res_ncloseinstead ofres_ndestroysince it was introduced in 8dd7984 but the FreeBSD support was removed in 1bd4895 and then brought back in fdd3293 so probably only the versions containingfdd3293 like 0.15 and 0.15.1 are affected.
Fixes
Closes #105