aboutsummaryrefslogtreecommitdiff
path: root/nis
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2005-12-08 04:12:07 +0000
committerUlrich Drepper <drepper@redhat.com>2005-12-08 04:12:07 +0000
commit07683f843da03675c1ddcd4810c72a9264f113dd (patch)
tree3f9326e2ab7627a2bddefc8a668e75781f662302 /nis
parent43bc8ac6eab0f952faa3f3ca7bd0adfcdba13d9a (diff)
downloadglibc-07683f843da03675c1ddcd4810c72a9264f113dd.tar
glibc-07683f843da03675c1ddcd4810c72a9264f113dd.tar.gz
glibc-07683f843da03675c1ddcd4810c72a9264f113dd.tar.bz2
glibc-07683f843da03675c1ddcd4810c72a9264f113dd.zip
* nis/nis_table.c (nis_list): Fix memory handling in error case.
2005-12-07 Ulrich Drepper <drepper@redhat.com> * nis/nis_table.c (nis_list): Remove have_tablepath, just use the pointer value itself.
Diffstat (limited to 'nis')
-rw-r--r--nis/nis_table.c79
1 files changed, 40 insertions, 39 deletions
diff --git a/nis/nis_table.c b/nis/nis_table.c
index 6761d37233..2ef28ac59b 100644
--- a/nis/nis_table.c
+++ b/nis/nis_table.c
@@ -164,8 +164,8 @@ nis_list (const_nis_name name, unsigned int flags,
nis_name namebuf[2] = {NULL, NULL};
int name_nr = 0;
nis_cb *cb = NULL;
- char *tableptr, *tablepath = NULL;
- int have_tablepath = 0;
+ char *tableptr;
+ char *tablepath = NULL;
int first_try = 0; /* Do we try the old binding at first ? */
if (res == NULL)
@@ -198,6 +198,7 @@ nis_list (const_nis_name name, unsigned int flags,
ibreq->ibr_name = strdup (names[name_nr]);
if (ibreq->ibr_name == NULL)
{
+ nis_freenames (names);
nis_free_request (ibreq);
NIS_RES_STATUS (res) = NIS_NOMEMORY;
return res;
@@ -220,30 +221,24 @@ nis_list (const_nis_name name, unsigned int flags,
status = __nisfind_server (ibreq->ibr_name, &dir);
if (status != NIS_SUCCESS)
- {
- nis_free_request (ibreq);
+ {
NIS_RES_STATUS (res) = status;
- return res;
- }
+ goto fail3;
+ }
status = __nisbind_create (&bptr, dir->do_servers.do_servers_val,
- dir->do_servers.do_servers_len, flags);
+ dir->do_servers.do_servers_len, flags);
if (status != NIS_SUCCESS)
{
- nis_free_request (ibreq);
NIS_RES_STATUS (res) = status;
- nis_free_directory (dir);
- return res;
+ goto fail2;
}
while (__nisbind_connect (&bptr) != NIS_SUCCESS)
if (__nisbind_next (&bptr) != NIS_SUCCESS)
{
- __nisbind_destroy (&bptr);
- nis_free_directory (dir);
- nis_free_request (ibreq);
NIS_RES_STATUS (res) = NIS_NAMEUNREACHABLE;
- return res;
+ goto fail;
}
if (callback != NULL)
@@ -284,8 +279,22 @@ nis_list (const_nis_name name, unsigned int flags,
strdup (NIS_RES_OBJECT (res)->LI_data.li_name);
if (ibreq->ibr_name == NULL)
{
- nis_free_request (ibreq);
NIS_RES_STATUS (res) = NIS_NOMEMORY;
+ fail:
+ __nisbind_destroy (&bptr);
+ fail2:
+ nis_free_directory (dir);
+ fail3:
+ free (tablepath);
+ if (cb)
+ {
+ __nis_destroy_callback (cb);
+ ibreq->ibr_cbhost.ibr_cbhost_len = 0;
+ ibreq->ibr_cbhost.ibr_cbhost_val = NULL;
+ }
+ if (names != namebuf)
+ nis_freenames (names);
+ nis_free_request (ibreq);
return res;
}
if (NIS_RES_OBJECT (res)->LI_data.li_attrs.li_attrs_len)
@@ -308,13 +317,7 @@ nis_list (const_nis_name name, unsigned int flags,
nis_freeresult (res);
res = calloc (1, sizeof (nis_result));
if (res == NULL)
- {
- if (have_tablepath)
- free (tablepath);
- __nisbind_destroy (&bptr);
- nis_free_directory (dir);
- return NULL;
- }
+ goto fail;
#endif
first_try = 1; /* Try at first the old binding */
goto again;
@@ -322,11 +325,10 @@ nis_list (const_nis_name name, unsigned int flags,
else if ((flags & FOLLOW_PATH)
&& NIS_RES_STATUS (res) == NIS_PARTIAL)
{
- if (!have_tablepath)
+ if (tablepath == NULL)
{
tablepath = __get_tablepath (ibreq->ibr_name, &bptr);
tableptr = tablepath;
- have_tablepath = 1;
}
if (tableptr == NULL)
{
@@ -340,9 +342,8 @@ nis_list (const_nis_name name, unsigned int flags,
ibreq->ibr_name = strdup ("");
if (ibreq->ibr_name == NULL)
{
- nis_free_request (ibreq);
NIS_RES_STATUS (res) = NIS_NOMEMORY;
- return res;
+ goto fail;
}
++done;
}
@@ -358,20 +359,20 @@ nis_list (const_nis_name name, unsigned int flags,
xdr_free ((xdrproc_t) _xdr_nis_result, (char *)res);
memset (res, '\0', sizeof (*res));
if (ibreq->ibr_name == NULL)
+ {
+ NIS_RES_STATUS (res) = NIS_NOMEMORY;
+ goto fail;
+ }
#else
nis_freeresult (res);
res = calloc (1, sizeof (nis_result));
if (res == NULL || ibreq->ibr_name == NULL)
-#endif
{
free (res);
- nis_free_request (ibreq);
- if (have_tablepath)
- free (tablepath);
- __nisbind_destroy (&bptr);
- nis_free_directory (dir);
- return NULL;
+ res = NULL;
+ goto fail;
}
+#endif
first_try = 1;
goto again;
}
@@ -389,11 +390,10 @@ nis_list (const_nis_name name, unsigned int flags,
++done;
else
{
- if (!have_tablepath)
+ if (tablepath == NULL)
{
tablepath = __get_tablepath (ibreq->ibr_name, &bptr);
tableptr = tablepath;
- have_tablepath = 1;
}
if (tableptr == NULL)
{
@@ -411,9 +411,8 @@ nis_list (const_nis_name name, unsigned int flags,
ibreq->ibr_name = strdup (ibreq->ibr_name);
if (ibreq->ibr_name == NULL)
{
- nis_free_request (ibreq);
NIS_RES_STATUS (res) = NIS_NOMEMORY;
- return res;
+ goto fail;
}
}
}
@@ -462,9 +461,8 @@ nis_list (const_nis_name name, unsigned int flags,
ibreq->ibr_name = strdup (names[name_nr]);
if (ibreq->ibr_name == NULL)
{
- nis_free_request (ibreq);
NIS_RES_STATUS (res) = NIS_NOMEMORY;
- return res;
+ goto fail;
}
first_try = 1; /* Try old binding at first */
goto again;
@@ -478,12 +476,15 @@ nis_list (const_nis_name name, unsigned int flags,
__nis_destroy_callback (cb);
ibreq->ibr_cbhost.ibr_cbhost_len = 0;
ibreq->ibr_cbhost.ibr_cbhost_val = NULL;
+ cb = NULL;
}
__nisbind_destroy (&bptr);
nis_free_directory (dir);
}
+ free (tablepath);
+
if (names != namebuf)
nis_freenames (names);