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

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


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

Re: [PATCH] Avoid res_nsend fd leaks


>>>>> Jakub Jelinek writes:

 > Hi!
 > res_nsend badly leaks filedescriptors.
 > A testcase is e.g.:

 > #include <netdb.h>
 > main()
 > {
 >   char * name = "acs.ac.sg";
 >   int i;

 >   for (i = 0; i < 1000; i++)
 >     gethostbyname(name);
 > }

 > The issue is that res_nclose clears _u._ext.nscount but it is initialized
 > only at the beginning of res_nsend, so if res_nclose is for some reason
 > called and res_nsend tries another nameserver and/or retries, next time
 > _u._ext.nscount will be 0 and thus res_nclose does not attempt to close any
 > sockets (and they get overwritten next time).
 > This patch attempts to solve this by separating two functions of nscount:
 > keeps it as count of IPv4 nameservers and moves the meaning that
 > initialization is needed on next res_nsend to new field nsinit.
 > Like this, res_nclose can be called as many times as it wishes from within
 > one res_nsend and no leaks happen.

Your patch enlarges struct __rest_state.  Can we easily do that
without breaking user programs?

res_state is used e.g. in:
int		res_ninit __P((res_state));

But it seems that the size of the struct isn't increased due to
alignment/padding, is that right?

Andreas
 > --- libc/resolv/resolv.h.jj	Thu Aug 10 09:39:05 2000
 > +++ libc/resolv/resolv.h	Wed Jan  3 23:32:23 2001
 > @@ -154,6 +154,7 @@ struct __res_state {
 >  			u_int16_t		nstimes[MAXNS];	/* ms. */
 >  			int			nssocks[MAXNS];
 >  			u_int16_t		nscount6;
 > +			u_int16_t		nsinit;
 >  			struct sockaddr_in6	*nsaddrs[MAXNS];
 >  		} _ext;
 >  	} _u;

 > 	Jakub


-- 
 Andreas Jaeger
  SuSE Labs aj@suse.de
   private aj@arthur.inka.de
    http://www.suse.de/~aj

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