Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak #17

Open
sustrik opened this issue Nov 7, 2016 · 1 comment
Open

Memory leak #17

sustrik opened this issue Nov 7, 2016 · 1 comment

Comments

@sustrik
Copy link

sustrik commented Nov 7, 2016

Test program:

#include "dns/dns.c"

int main() {
    int rc;
    struct dns_resolv_conf *dns_conf = dns_resconf_local(&rc);
    assert(dns_conf);
    struct dns_hosts *dns_hosts = dns_hosts_local(&rc);
    assert(dns_hosts);
    struct dns_hints *dns_hints = dns_hints_local(dns_conf, &rc);
    assert(dns_hints);
    struct dns_resolver *resolver = dns_res_open(dns_conf, dns_hosts, dns_hints, NULL, dns_opts(), &rc);
    assert(resolver);
    struct addrinfo hints;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = PF_INET;
    struct dns_addrinfo *ai = dns_ai_open("example.org", "80", DNS_T_A, &hints, resolver, &rc);
    assert(ai);
    struct addrinfo *it = NULL;
    while(1) {
        rc = dns_ai_nextent(&it, ai);
        if(rc == EAGAIN) {
            rc = dns_res_poll(resolver, -1);
            assert(rc == 0);
            continue;
        }
        if(rc == ENOENT)
            break;
    }
    dns_ai_close(ai);
    dns_res_close(resolver);
    dns_hints_close(dns_hints);
    dns_hosts_close(dns_hosts);
    dns_resconf_close(dns_conf);
    return 0;
}

Valgrind output:

$ valgrind --leak-check=full ./test
==18871== Memcheck, a memory error detector
==18871== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==18871== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==18871== Command: ./test
==18871== 
==18871== 
==18871== HEAP SUMMARY:
==18871==     in use at exit: 64 bytes in 1 blocks
==18871==   total heap usage: 28 allocs, 27 frees, 16,838 bytes allocated
==18871== 
==18871== 64 bytes in 1 blocks are definitely lost in loss record 1 of 1
==18871==    at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==18871==    by 0x4130DC: dns_ai_setent (in /home/sustrik/dsock/test)
==18871==    by 0x4137A2: dns_ai_nextent (in /home/sustrik/dsock/test)
==18871==    by 0x414D6B: main (in /home/sustrik/dsock/test)
==18871== 
==18871== LEAK SUMMARY:
==18871==    definitely lost: 64 bytes in 1 blocks
==18871==    indirectly lost: 0 bytes in 0 blocks
==18871==      possibly lost: 0 bytes in 0 blocks
==18871==    still reachable: 0 bytes in 0 blocks
==18871==         suppressed: 0 bytes in 0 blocks
==18871== 
==18871== For counts of detected and suppressed errors, rerun with: -v
==18871== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
@sustrik
Copy link
Author

sustrik commented Apr 8, 2017

It seems that entries returned dns_ai_nextent should be free()'d. If so, it would be nice if the documentation said so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant