This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Memory leak in the resolver (threads)


I received an interesting bug report about a small memory leak in the
resolver.  Suppose that you have an application which creates a new thread
every time it wants to do a DNS lookup.  In the course of the request, some
memory is allocated, in __libc_res_nsend:

                for (ns = 0; ns < EXT(statp).nscount; ns++) {
                        n = map[ns];
                        if (EXT(statp).nsaddrs[n] == NULL)
                                EXT(statp).nsaddrs[n] =
                                    malloc(sizeof (struct sockaddr_in6));
                        if (EXT(statp).nsaddrs[n] != NULL) {
                                memcpy(EXT(statp).nsaddrs[n],
                                       &statp->nsaddr_list[ns],
                                       sizeof (struct sockaddr_in));
                                EXT(statp).nssocks[n] = -1;
                                n++;
                        }
                }

A sockaddr per nameserver.  I can't see a logical place to free this
data, so when the thread exits, it is leaked.  Does anyone have a suggestion
on how to clean this up?

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]