I've just found that under heavy load ypldap's LDAP engine leaks
file descriptors. I'll try to post issues I found one-by-one,
and here is the first leak I've found.

This fixes an fd leak happening if aldap_init() returns NULL. Okay?

--
WBR,
  Vadim Zhukov


Index: ldapclient.c
===================================================================
RCS file: /cvs/src/usr.sbin/ypldap/ldapclient.c,v
retrieving revision 1.39
diff -u -p -r1.39 ldapclient.c
--- ldapclient.c        30 May 2017 09:33:31 -0000      1.39
+++ ldapclient.c        6 Dec 2017 12:43:57 -0000
@@ -66,7 +66,8 @@ struct aldap *
 client_aldap_open(struct ypldap_addr_list *addr)
 {
        int                      fd = -1;
-       struct ypldap_addr       *p;
+       struct ypldap_addr      *p;
+       struct aldap            *al;
 
        TAILQ_FOREACH(p, addr, next) {
                char                     hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
@@ -90,7 +91,10 @@ client_aldap_open(struct ypldap_addr_lis
        if (fd == -1)
                return NULL;
 
-       return aldap_init(fd);
+       al = aldap_init(fd);
+       if (al == NULL)
+               close(fd);
+       return al;
 }
 
 int

Reply via email to