about summary refs log tree commit diff
path: root/nis/nis_getservlist.c
diff options
context:
space:
mode:
Diffstat (limited to 'nis/nis_getservlist.c')
-rw-r--r--nis/nis_getservlist.c57
1 files changed, 12 insertions, 45 deletions
diff --git a/nis/nis_getservlist.c b/nis/nis_getservlist.c
index e57649d526..315960c8e8 100644
--- a/nis/nis_getservlist.c
+++ b/nis/nis_getservlist.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 1999, 2000, 2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
 
@@ -40,10 +40,7 @@ nis_getservlist (const_nis_name dir)
 	malloc (sizeof (nis_server *) *
 		(NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_len + 1));
       if (__builtin_expect (serv == NULL, 0))
-	{
-	  nis_freeresult (res);
-	  return NULL;
-	}
+	return NULL;
 
       for (i = 0; i < NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_len;
 	   ++i)
@@ -52,41 +49,13 @@ nis_getservlist (const_nis_name dir)
 	    &NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_val[i];
 	  serv[i] = calloc (1, sizeof (nis_server));
 	  if (__builtin_expect (serv[i] == NULL, 0))
-	    {
-	    free_all:
-	      while (i-- > 0)
-		{
-		  free (serv[i]->pkey.n_bytes);
-		  if (serv[i]->ep.ep_val != NULL)
-		    {
-		      unsigned long int j;
-		      for (j = 0; j < serv[i]->ep.ep_len; ++j)
-			{
-			  free (serv[i]->ep.ep_val[j].proto);
-			  free (serv[i]->ep.ep_val[j].family);
-			  free (serv[i]->ep.ep_val[j].uaddr);
-			}
-		      free (serv[i]->ep.ep_val);
-		    }
-		  free (serv[i]->name);
-		  free (serv[i]);
-		}
-
-	      free (serv);
-
-	      nis_freeresult (res);
-
-	      return NULL;
-	    }
+	    return NULL;
 
 	  if (server->name != NULL)
 	    {
 	      serv[i]->name = strdup (server->name);
 	      if (__builtin_expect (serv[i]->name == NULL, 0))
-		{
-		  ++i;
-		  goto free_all;
-		}
+		return NULL;
 	    }
 
           serv[i]->ep.ep_len = server->ep.ep_len;
@@ -97,10 +66,7 @@ nis_getservlist (const_nis_name dir)
               serv[i]->ep.ep_val =
 		malloc (server->ep.ep_len * sizeof (endpoint));
 	      if (__builtin_expect (serv[i]->ep.ep_val == NULL, 0))
-		{
-		  ++i;
-		  goto free_all;
-		}
+		return NULL;
 
               for (j = 0; j < serv[i]->ep.ep_len; ++j)
                 {
@@ -121,20 +87,20 @@ nis_getservlist (const_nis_name dir)
 		    serv[i]->ep.ep_val[j].proto = NULL;
                 }
             }
-
+          else
+	    serv[i]->ep.ep_val = NULL;
           serv[i]->key_type = server->key_type;
           serv[i]->pkey.n_len = server->pkey.n_len;
           if (server->pkey.n_len > 0)
             {
               serv[i]->pkey.n_bytes = malloc (server->pkey.n_len);
               if (__builtin_expect (serv[i]->pkey.n_bytes == NULL, 0))
-		{
-		  ++i;
-		  goto free_all;
-		}
+                return NULL;
               memcpy (serv[i]->pkey.n_bytes, server->pkey.n_bytes,
                       server->pkey.n_len);
             }
+          else
+            serv[i]->pkey.n_bytes = NULL;
         }
       serv[i] = NULL;
     }
@@ -145,7 +111,8 @@ nis_getservlist (const_nis_name dir)
 	serv[0] = NULL;
     }
 
-  nis_freeresult (res);
+  if (res != NULL)
+    nis_freeresult (res);
 
   return serv;
 }