Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/mountd avoid memory leak and duplicated free.



details:   https://anonhg.NetBSD.org/src/rev/dbaaa11908dc
branches:  trunk
changeset: 487805:dbaaa11908dc
user:      itojun <itojun%NetBSD.org@localhost>
date:      Tue Jun 13 01:08:43 2000 +0000

description:
avoid memory leak and duplicated free.

diffstat:

 usr.sbin/mountd/mountd.c |  27 ++++++++++++---------------
 1 files changed, 12 insertions(+), 15 deletions(-)

diffs (77 lines):

diff -r 6d9f775c8237 -r dbaaa11908dc usr.sbin/mountd/mountd.c
--- a/usr.sbin/mountd/mountd.c  Tue Jun 13 01:02:44 2000 +0000
+++ b/usr.sbin/mountd/mountd.c  Tue Jun 13 01:08:43 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mountd.c,v 1.67 2000/06/10 08:01:07 itojun Exp $        */
+/*     $NetBSD: mountd.c,v 1.68 2000/06/13 01:08:43 itojun Exp $        */
 
 /*
  * Copyright (c) 1989, 1993
@@ -51,7 +51,7 @@
 #if 0
 static char     sccsid[] = "@(#)mountd.c  8.15 (Berkeley) 5/1/95";
 #else
-__RCSID("$NetBSD: mountd.c,v 1.67 2000/06/10 08:01:07 itojun Exp $");
+__RCSID("$NetBSD: mountd.c,v 1.68 2000/06/13 01:08:43 itojun Exp $");
 #endif
 #endif                         /* not lint */
 
@@ -2124,14 +2124,14 @@
                if (getaddrinfo(cp, NULL, &hints, &ai) == 0)
                        sa = ai->ai_addr;
                else
-                       return 1;
+                       goto fail;
        } else
-               return 1;
+               goto fail;
 
        ecode = getnameinfo(sa, sa->sa_len, netname, sizeof netname,
            NULL, 0, NI_NUMERICHOST);
        if (ecode != 0)
-               return 1;
+               goto fail;
 
        if (maskflg)
                net->nt_len = countones(sa);
@@ -2139,7 +2139,7 @@
                if (opt_flags & OP_MASKLEN) {
                        preflen = strtol(prefp, NULL, 10);
                        if (preflen == LONG_MIN && errno == ERANGE)
-                               return 1;
+                               goto fail;
                        net->nt_len = (int)preflen;
                        *p = '/';
                }
@@ -2173,6 +2173,11 @@
        if (ai)
                freeaddrinfo(ai);
        return 0;
+
+fail:
+       if (ai)
+               freeaddrinfo(ai);
+       return 1;
 }
 
 /*
@@ -2427,18 +2432,10 @@
 free_grp(grp)
        struct grouplist *grp;
 {
-       struct addrinfo *ai;
 
        if (grp->gr_type == GT_HOST) {
-               if (grp->gr_ptr.gt_addrinfo != NULL) {
-                       ai = grp->gr_ptr.gt_addrinfo;
-                       do {
-                               if (ai->ai_flags & AI_CANONNAME)
-                                       free(ai->ai_canonname);
-                               ai = ai->ai_next;
-                       } while (ai != NULL);
+               if (grp->gr_ptr.gt_addrinfo != NULL)
                        freeaddrinfo(grp->gr_ptr.gt_addrinfo);
-               }
        } else if (grp->gr_type == GT_NET) {
                if (grp->gr_ptr.gt_net.nt_name)
                        free(grp->gr_ptr.gt_net.nt_name);



Home | Main Index | Thread Index | Old Index