diff options
author | Ulrich Drepper <drepper@redhat.com> | 2006-05-10 02:55:21 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2006-05-10 02:55:21 +0000 |
commit | 51e5926049360b991d71862e33a97fe1ead4d9a6 (patch) | |
tree | 3089a8fec8cd11641d803075a15c7bdb51f4976b /nis/nis_lookup.c | |
parent | e7c8359e431ef305fbc61e4b86af6353b4f39879 (diff) | |
download | glibc-51e5926049360b991d71862e33a97fe1ead4d9a6.zip glibc-51e5926049360b991d71862e33a97fe1ead4d9a6.tar.gz glibc-51e5926049360b991d71862e33a97fe1ead4d9a6.tar.bz2 |
* nis/nis_defaults.c (searchXYX): New functions. Used by both
searchgroup and searchowner. Significantly simplified.
(__nis_default_owner): Remove duplication. Do not locally copy the
string before duplicating it.
(__nis_default_group): Likewise.
* nis/nis_lookup.c (nis_lookup): After calling nis_free_directory,
we must clear the variable before calling __nisfind_server.
* nis/nis_lookup.c (nis_lookup): Always free memory allocated with
nis_getnames. [Coverity CID 223]
* locale/programs/locfile.c (locfile_read): Use alloca instead of
xmalloc to allocate local repertoire name. [Coverity CID 222]
* iconv/iconv_charmap.c (use_to_charmap): No need to dynamically
allocate memory for the input to add_bytes. [Coverity CID 221]
was allocated here. [Coverity CID 219, 220]
Diffstat (limited to 'nis/nis_lookup.c')
-rw-r--r-- | nis/nis_lookup.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/nis/nis_lookup.c b/nis/nis_lookup.c index 4cb34dd..821b9bc 100644 --- a/nis/nis_lookup.c +++ b/nis/nis_lookup.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1997, 1998, 1999, 2004, 2005 Free Software Foundation, Inc. +/* Copyright (C) 1997-1999, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Thorsten Kukuk <kukuk@uni-paderborn.de>, 1997. @@ -65,7 +65,7 @@ nis_lookup (const_nis_name name, const unsigned int flags) if (status != NIS_SUCCESS) { NIS_RES_STATUS (res) = status; - return res; + goto out; } status = __nisbind_create (&bptr, dir->do_servers.do_servers_val, @@ -74,7 +74,7 @@ nis_lookup (const_nis_name name, const unsigned int flags) { NIS_RES_STATUS (res) = status; nis_free_directory (dir); - return res; + goto out;; } while (__nisbind_connect (&bptr) != NIS_SUCCESS) @@ -83,7 +83,7 @@ nis_lookup (const_nis_name name, const unsigned int flags) { nis_free_directory (dir); NIS_RES_STATUS (res) = NIS_NAMEUNREACHABLE; - return res; + goto out; } } @@ -121,8 +121,21 @@ nis_lookup (const_nis_name name, const unsigned int flags) req.ns_name = strdup (NIS_RES_OBJECT (res)->LI_data.li_name); if (req.ns_name == NULL) - return NULL; + { + nis_free_directory (dir); + res = NULL; + goto out; + } + /* The following is a non-obvious optimization. A + nis_freeresult call would call xdr_free as the + following code. But it also would unnecessarily + free the result structure. We avoid this here + along with the necessary tests. */ +#if 1 + xdr_free ((xdrproc_t) _xdr_nis_result, (char *) res); + memset (res, '\0', sizeof (*res)); +#else nis_freeresult (res); res = calloc (1, sizeof (nis_result)); if (res == NULL) @@ -130,6 +143,7 @@ nis_lookup (const_nis_name name, const unsigned int flags) __nisbind_destroy (&bptr); return NULL; } +#endif link_first_try = 1; /* Try at first the old binding */ goto again; @@ -144,10 +158,12 @@ nis_lookup (const_nis_name name, const unsigned int flags) { __nisbind_destroy (&bptr); nis_free_directory (dir); + /* Otherwise __nisfind_server will not do anything. */ + dir = NULL; if (__nisfind_server (req.ns_name, &dir) != NIS_SUCCESS) - return res; + goto out; if (__nisbind_create (&bptr, dir->do_servers.do_servers_val, @@ -155,7 +171,7 @@ nis_lookup (const_nis_name name, const unsigned int flags) flags) != NIS_SUCCESS) { nis_free_directory (dir); - return res; + goto out; } } else @@ -167,7 +183,7 @@ nis_lookup (const_nis_name name, const unsigned int flags) if (__nisbind_next (&bptr) != NIS_SUCCESS) { nis_free_directory (dir); - return res; + goto out; } } goto again; @@ -184,7 +200,7 @@ nis_lookup (const_nis_name name, const unsigned int flags) if (status != NIS_SUCCESS) { NIS_RES_STATUS (res) = status; - return res; + goto out; } switch (NIS_RES_STATUS (res)) @@ -216,6 +232,7 @@ nis_lookup (const_nis_name name, const unsigned int flags) } } + out: if (names != namebuf) nis_freenames (names); |