about summary refs log tree commit diff
path: root/nis/nss_nis/nis-ethers.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-03-29 21:46:58 +0000
committerUlrich Drepper <drepper@redhat.com>2004-03-29 21:46:58 +0000
commitb569ae384410aeff8bf3252eca64df1686bcd70a (patch)
treea7aec1e0aac1736f50a662b302f39602f50bb3fb /nis/nss_nis/nis-ethers.c
parent95479dc273d889da860a94fc28cb5683d98189e1 (diff)
downloadglibc-b569ae384410aeff8bf3252eca64df1686bcd70a.tar.gz
glibc-b569ae384410aeff8bf3252eca64df1686bcd70a.tar.xz
glibc-b569ae384410aeff8bf3252eca64df1686bcd70a.zip
Update.
	* nis/nss_nis/nis-rpc.c (saveit): Improve memory.  No need to
	allocate multiple blocks.
	(internal_nis_endrpcent): Adjust accordingly.
	* nis/nss_nis/nis-proto.c (saveit): Improve memory.  No need to
	allocate multiple blocks.
	(internal_nis_endprotoent): Adjust accordingly.
	* nis/nss_nis/nis-initgroups.c (saveit): Improve memory.  No need
	to allocate multiple blocks.
	(_nss_nis_initgroups_dyn): Adjust accordingly.
	* nis/nss_nis/nis-ethers.c (saveit): Improve memory.  No need to
	allocate multiple blocks.
	(internal_nis_endetherent): Adjust accordingly.
	* nis/nss_nis/nis-service.c (saveit): Improve memory.  No need to
	allocate multiple blocks.
	(internal_nis_endservent): Adjust accordingly.
Diffstat (limited to 'nis/nss_nis/nis-ethers.c')
-rw-r--r--nis/nss_nis/nis-ethers.c34
1 files changed, 12 insertions, 22 deletions
diff --git a/nis/nss_nis/nis-ethers.c b/nis/nss_nis/nis-ethers.c
index 713fe31e93..328d61f6c5 100644
--- a/nis/nss_nis/nis-ethers.c
+++ b/nis/nss_nis/nis-ethers.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2003, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -40,8 +40,8 @@ __libc_lock_define_initialized (static, lock)
 
 struct response
 {
-  char *val;
   struct response *next;
+  char val[0];
 };
 
 static struct response *start;
@@ -56,26 +56,18 @@ saveit (int instatus, char *inkey, int inkeylen, char *inval,
 
   if (inkey && inkeylen > 0 && inval && invallen > 0)
     {
+      struct response *newp = malloc (sizeof (struct response) + invallen + 1);
+      if (newp == NULL)
+	return YP_FALSE; /* We have no error code for out of memory */
+
       if (start == NULL)
-	{
-	  start = malloc (sizeof (struct response));
-	  if (start == NULL)
-	    return YP_FALSE;
-	  next = start;
-	}
+	start = newp;
       else
-	{
-	  next->next = malloc (sizeof (struct response));
-	  if (next->next == NULL)
-	    return YP_FALSE;
-	  next = next->next;
-	}
-      next->next = NULL;
-      next->val = malloc (invallen + 1);
-      if (next->val == NULL)
-	return YP_FALSE;
-      strncpy (next->val, inval, invallen);
-      next->val[invallen] = '\0';
+	next->next = newp;
+      next = newp;
+
+      newp->next = NULL;
+      *((char *) mempcpy (newp->val, inval, invallen)) = '\0';
     }
 
   return 0;
@@ -86,8 +78,6 @@ internal_nis_endetherent (void)
 {
   while (start != NULL)
     {
-      if (start->val != NULL)
-	free (start->val);
       next = start;
       start = start->next;
       free (next);