memory leak in resolver

Dag-Erling Smørgrav des at des.no
Wed Feb 16 03:16:52 PST 2005


des at xps ~/src/gai% cat gai.c
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <string.h>

int
main(void)
{
        struct addrinfo hint, *res;

        memset(&hint, 0, sizeof(hint));
        hint.ai_family = AF_INET;
        hint.ai_socktype = SOCK_STREAM;
        hint.ai_protocol = 0;
        if (getaddrinfo("www.freebsd.org", "http", &hint, &res) == 0)
                freeaddrinfo(res);
        return (0);
}
des at xps ~/src/gai% valgrind --leak-check=yes --num-callers=8 ./gai
==44998== Memcheck, a memory error detector for x86-linux.
==44998== Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward.
==44998== Using valgrind-2.1.0, a program supervision framework for x86-linux.
==44998== Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward.
==44998== Estimated CPU clock rate is 3591 MHz
==44998== For more details, rerun with: -v
==44998==
==44998==
==44998== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==44998== malloc/free: in use at exit: 2328 bytes in 11 blocks.
==44998== malloc/free: 45 allocs, 34 frees, 232569 bytes allocated.
==44998== For counts of detected errors, rerun with: -v
==44998== searching for pointers to 11 not-freed blocks.
==44998== checked 1258740 bytes.
==44998==
==44998== 49 bytes in 5 blocks are definitely lost in loss record 2 of 5
==44998==    at 0x3C033173: malloc (vg_replace_malloc.c:105)
==44998==    by 0x3C0D567E: strdup (strdup.c:52)
==44998==    by 0x3C0D0403: _nsyylex (nslexer.l:88)
==44998==    by 0x3C0CF903: _nsyyparse (y.tab.c:380)
==44998==    by 0x3C0D296E: _nsdispatch (nsdispatch.c:353)
==44998==    by 0x3C0C6E33: getaddrinfo (getaddrinfo.c:1646)
==44998==    by 0x804856C: main (gai.c:15)
==44998==
==44998== LEAK SUMMARY:
==44998==    definitely lost: 49 bytes in 5 blocks.
==44998==    possibly lost:   0 bytes in 0 blocks.
==44998==    still reachable: 2279 bytes in 6 blocks.
==44998==         suppressed: 0 bytes in 0 blocks.
==44998== Reachable blocks (those to which a pointer was found) are not shown.
==44998== To see them, rerun with: --show-reachable=yes

The amount of memory leaked seems constant regardless of how many
times getaddrinfo() is called, so it's probably from reading
resolv.conf.

DES
-- 
Dag-Erling Smørgrav - des at des.no


More information about the freebsd-hackers mailing list