1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-09-07 01:26:44 +03:00

* 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.
This commit is contained in:
Ulrich Drepper
2005-12-08 04:12:07 +00:00
parent 43bc8ac6ea
commit 07683f843d
2 changed files with 49 additions and 39 deletions

View File

@@ -1,3 +1,12 @@
2005-12-07 Jakub Jelinek <jakub@redhat.com>
* 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.
2005-12-06 Ulrich Drepper <drepper@redhat.com> 2005-12-06 Ulrich Drepper <drepper@redhat.com>
* catgets/gencat.c: Use GPL, not LGPL. * catgets/gencat.c: Use GPL, not LGPL.

View File

@@ -164,8 +164,8 @@ nis_list (const_nis_name name, unsigned int flags,
nis_name namebuf[2] = {NULL, NULL}; nis_name namebuf[2] = {NULL, NULL};
int name_nr = 0; int name_nr = 0;
nis_cb *cb = NULL; nis_cb *cb = NULL;
char *tableptr, *tablepath = NULL; char *tableptr;
int have_tablepath = 0; char *tablepath = NULL;
int first_try = 0; /* Do we try the old binding at first ? */ int first_try = 0; /* Do we try the old binding at first ? */
if (res == NULL) if (res == NULL)
@@ -198,6 +198,7 @@ nis_list (const_nis_name name, unsigned int flags,
ibreq->ibr_name = strdup (names[name_nr]); ibreq->ibr_name = strdup (names[name_nr]);
if (ibreq->ibr_name == NULL) if (ibreq->ibr_name == NULL)
{ {
nis_freenames (names);
nis_free_request (ibreq); nis_free_request (ibreq);
NIS_RES_STATUS (res) = NIS_NOMEMORY; NIS_RES_STATUS (res) = NIS_NOMEMORY;
return res; return res;
@@ -220,30 +221,24 @@ nis_list (const_nis_name name, unsigned int flags,
status = __nisfind_server (ibreq->ibr_name, &dir); status = __nisfind_server (ibreq->ibr_name, &dir);
if (status != NIS_SUCCESS) if (status != NIS_SUCCESS)
{ {
nis_free_request (ibreq);
NIS_RES_STATUS (res) = status; NIS_RES_STATUS (res) = status;
return res; goto fail3;
} }
status = __nisbind_create (&bptr, dir->do_servers.do_servers_val, 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) if (status != NIS_SUCCESS)
{ {
nis_free_request (ibreq);
NIS_RES_STATUS (res) = status; NIS_RES_STATUS (res) = status;
nis_free_directory (dir); goto fail2;
return res;
} }
while (__nisbind_connect (&bptr) != NIS_SUCCESS) while (__nisbind_connect (&bptr) != NIS_SUCCESS)
if (__nisbind_next (&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; NIS_RES_STATUS (res) = NIS_NAMEUNREACHABLE;
return res; goto fail;
} }
if (callback != NULL) 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); strdup (NIS_RES_OBJECT (res)->LI_data.li_name);
if (ibreq->ibr_name == NULL) if (ibreq->ibr_name == NULL)
{ {
nis_free_request (ibreq);
NIS_RES_STATUS (res) = NIS_NOMEMORY; 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; return res;
} }
if (NIS_RES_OBJECT (res)->LI_data.li_attrs.li_attrs_len) 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); nis_freeresult (res);
res = calloc (1, sizeof (nis_result)); res = calloc (1, sizeof (nis_result));
if (res == NULL) if (res == NULL)
{ goto fail;
if (have_tablepath)
free (tablepath);
__nisbind_destroy (&bptr);
nis_free_directory (dir);
return NULL;
}
#endif #endif
first_try = 1; /* Try at first the old binding */ first_try = 1; /* Try at first the old binding */
goto again; goto again;
@@ -322,11 +325,10 @@ nis_list (const_nis_name name, unsigned int flags,
else if ((flags & FOLLOW_PATH) else if ((flags & FOLLOW_PATH)
&& NIS_RES_STATUS (res) == NIS_PARTIAL) && NIS_RES_STATUS (res) == NIS_PARTIAL)
{ {
if (!have_tablepath) if (tablepath == NULL)
{ {
tablepath = __get_tablepath (ibreq->ibr_name, &bptr); tablepath = __get_tablepath (ibreq->ibr_name, &bptr);
tableptr = tablepath; tableptr = tablepath;
have_tablepath = 1;
} }
if (tableptr == NULL) if (tableptr == NULL)
{ {
@@ -340,9 +342,8 @@ nis_list (const_nis_name name, unsigned int flags,
ibreq->ibr_name = strdup (""); ibreq->ibr_name = strdup ("");
if (ibreq->ibr_name == NULL) if (ibreq->ibr_name == NULL)
{ {
nis_free_request (ibreq);
NIS_RES_STATUS (res) = NIS_NOMEMORY; NIS_RES_STATUS (res) = NIS_NOMEMORY;
return res; goto fail;
} }
++done; ++done;
} }
@@ -358,20 +359,20 @@ nis_list (const_nis_name name, unsigned int flags,
xdr_free ((xdrproc_t) _xdr_nis_result, (char *)res); xdr_free ((xdrproc_t) _xdr_nis_result, (char *)res);
memset (res, '\0', sizeof (*res)); memset (res, '\0', sizeof (*res));
if (ibreq->ibr_name == NULL) if (ibreq->ibr_name == NULL)
{
NIS_RES_STATUS (res) = NIS_NOMEMORY;
goto fail;
}
#else #else
nis_freeresult (res); nis_freeresult (res);
res = calloc (1, sizeof (nis_result)); res = calloc (1, sizeof (nis_result));
if (res == NULL || ibreq->ibr_name == NULL) if (res == NULL || ibreq->ibr_name == NULL)
#endif
{ {
free (res); free (res);
nis_free_request (ibreq); res = NULL;
if (have_tablepath) goto fail;
free (tablepath);
__nisbind_destroy (&bptr);
nis_free_directory (dir);
return NULL;
} }
#endif
first_try = 1; first_try = 1;
goto again; goto again;
} }
@@ -389,11 +390,10 @@ nis_list (const_nis_name name, unsigned int flags,
++done; ++done;
else else
{ {
if (!have_tablepath) if (tablepath == NULL)
{ {
tablepath = __get_tablepath (ibreq->ibr_name, &bptr); tablepath = __get_tablepath (ibreq->ibr_name, &bptr);
tableptr = tablepath; tableptr = tablepath;
have_tablepath = 1;
} }
if (tableptr == NULL) if (tableptr == NULL)
{ {
@@ -411,9 +411,8 @@ nis_list (const_nis_name name, unsigned int flags,
ibreq->ibr_name = strdup (ibreq->ibr_name); ibreq->ibr_name = strdup (ibreq->ibr_name);
if (ibreq->ibr_name == NULL) if (ibreq->ibr_name == NULL)
{ {
nis_free_request (ibreq);
NIS_RES_STATUS (res) = NIS_NOMEMORY; 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]); ibreq->ibr_name = strdup (names[name_nr]);
if (ibreq->ibr_name == NULL) if (ibreq->ibr_name == NULL)
{ {
nis_free_request (ibreq);
NIS_RES_STATUS (res) = NIS_NOMEMORY; NIS_RES_STATUS (res) = NIS_NOMEMORY;
return res; goto fail;
} }
first_try = 1; /* Try old binding at first */ first_try = 1; /* Try old binding at first */
goto again; goto again;
@@ -478,12 +476,15 @@ nis_list (const_nis_name name, unsigned int flags,
__nis_destroy_callback (cb); __nis_destroy_callback (cb);
ibreq->ibr_cbhost.ibr_cbhost_len = 0; ibreq->ibr_cbhost.ibr_cbhost_len = 0;
ibreq->ibr_cbhost.ibr_cbhost_val = NULL; ibreq->ibr_cbhost.ibr_cbhost_val = NULL;
cb = NULL;
} }
__nisbind_destroy (&bptr); __nisbind_destroy (&bptr);
nis_free_directory (dir); nis_free_directory (dir);
} }
free (tablepath);
if (names != namebuf) if (names != namebuf)
nis_freenames (names); nis_freenames (names);