diff options
author | Ulrich Drepper <drepper@redhat.com> | 2004-08-13 20:26:29 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2004-08-13 20:26:29 +0000 |
commit | 2486480e23051b536fa2ac612b0613105ba988cf (patch) | |
tree | a04339514598f842fc616422e82ea71742ce9143 /inet | |
parent | b8b9340e6f26ef1b19c983fa481b75fd12c01d1b (diff) | |
download | glibc-2486480e23051b536fa2ac612b0613105ba988cf.tar.gz |
Update.
* inet/netgroup.h (struct name_list): Replace name pointer with
zero-sized array.
* inet/getnetgrent_r.c: Adjust code for change in name_list
layout. Numerous strdup and free calls removed.
Diffstat (limited to 'inet')
-rw-r--r-- | inet/getnetgrent_r.c | 40 | ||||
-rw-r--r-- | inet/netgroup.h | 4 |
2 files changed, 19 insertions, 25 deletions
diff --git a/inet/getnetgrent_r.c b/inet/getnetgrent_r.c index 5531844d14..fa355b210e 100644 --- a/inet/getnetgrent_r.c +++ b/inet/getnetgrent_r.c @@ -78,7 +78,6 @@ free_memory (struct __netgrent *data) { struct name_list *tmp = data->known_groups; data->known_groups = data->known_groups->next; - free ((void *) tmp->name); free (tmp); } @@ -86,7 +85,6 @@ free_memory (struct __netgrent *data) { struct name_list *tmp = data->needed_groups; data->needed_groups = data->needed_groups->next; - free ((void *) tmp->name); free (tmp); } } @@ -116,17 +114,18 @@ __internal_setnetgrent_reuse (const char *group, struct __netgrent *datap, } /* Add the current group to the list of known groups. */ - new_elem = (struct name_list *) malloc (sizeof (struct name_list)); - if (new_elem == NULL || (new_elem->name = __strdup (group)) == NULL) + size_t group_len = strlen (group) + 1; + new_elem = (struct name_list *) malloc (sizeof (struct name_list) + + group_len); + if (new_elem == NULL) { - if (new_elem != NULL) - free (new_elem); *errnop = errno; status = NSS_STATUS_TRYAGAIN; } else { new_elem->next = datap->known_groups; + memcpy (new_elem->name, group, group_len); datap->known_groups = new_elem; } @@ -269,18 +268,16 @@ internal_getnetgrent_r (char **hostp, char **userp, char **domainp, /* Really ignore. */ continue; - namep = (struct name_list *) malloc (sizeof (struct name_list)); - if (namep == NULL - || (namep->name = __strdup (datap->val.group)) == NULL) - { - /* We are out of memory. */ - if (namep != NULL) - free (namep); - status = NSS_STATUS_RETURN; - } + size_t group_len = strlen (datap->val.group) + 1; + namep = (struct name_list *) malloc (sizeof (struct name_list) + + group_len); + if (namep == NULL) + /* We are out of memory. */ + status = NSS_STATUS_RETURN; else { namep->next = datap->needed_groups; + memcpy (namep->name, datap->val.group, group_len); datap->needed_groups = namep; /* And get the next entry. */ continue; @@ -383,20 +380,19 @@ innetgr (const char *netgroup, const char *host, const char *user, if (namep == NULL && strcmp (netgroup, entry.val.group) != 0) { + size_t group_len = strlen (entry.val.group) + 1; namep = - (struct name_list *) malloc (sizeof (*namep)); - if (namep == NULL - || ((namep->name = __strdup (entry.val.group)) - == NULL)) + (struct name_list *) malloc (sizeof (*namep) + + group_len); + if (namep == NULL) { /* Out of memory, simply return. */ - if (namep != NULL) - free (namep); result = -1; break; } namep->next = needed; + memcpy (namep->name, entry.val.group, group_len); needed = namep; } } @@ -454,14 +450,12 @@ innetgr (const char *netgroup, const char *host, const char *user, { struct name_list *tmp = known; known = known->next; - free ((void *) tmp->name); free (tmp); } while (needed != NULL) { struct name_list *tmp = needed; needed = needed->next; - free ((void *) tmp->name); free (tmp); } diff --git a/inet/netgroup.h b/inet/netgroup.h index 90a8d450f7..aea52188d9 100644 --- a/inet/netgroup.h +++ b/inet/netgroup.h @@ -1,5 +1,5 @@ /* Internal header for netgroup related functions. - Copyright (C) 1996, 1997 Free Software Foundation, Inc. + Copyright (C) 1996, 1997, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -24,8 +24,8 @@ track which netgroups were read and which still have to be read. */ struct name_list { - const char *name; struct name_list *next; + char name[0]; }; |