diff options
author | Ulrich Drepper <drepper@redhat.com> | 1999-05-14 23:38:21 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 1999-05-14 23:38:21 +0000 |
commit | 843ede44f78a91de84613f7581efadb13dbc6d25 (patch) | |
tree | a0b7d96433062ff25d96994ba9aec288d4629f91 /nis | |
parent | 1483b7537883c00276b91f8c35496594edd5b073 (diff) | |
download | glibc-843ede44f78a91de84613f7581efadb13dbc6d25.zip glibc-843ede44f78a91de84613f7581efadb13dbc6d25.tar.gz glibc-843ede44f78a91de84613f7581efadb13dbc6d25.tar.bz2 |
Update.
1999-05-14 Ulrich Drepper <drepper@cygnus.com>
* nis/nis_getservlist.c (nis_getservlist): Use malloc instead of
calloc.
* nis/nis_checkpoint.c (nis_checkpoint): Fix memory leaks.
* nis/nis_addmember.c (nis_addmember): Fix memory leak. Test
memory allocation results.
Diffstat (limited to 'nis')
-rw-r--r-- | nis/nis_addmember.c | 16 | ||||
-rw-r--r-- | nis/nis_checkpoint.c | 8 | ||||
-rw-r--r-- | nis/nis_getservlist.c | 12 |
3 files changed, 29 insertions, 7 deletions
diff --git a/nis/nis_addmember.c b/nis/nis_addmember.c index 2a31903..3f1c2b3 100644 --- a/nis/nis_addmember.c +++ b/nis/nis_addmember.c @@ -1,4 +1,4 @@ -/* Copyright (c) 1997, 1998 Free Software Foundation, Inc. +/* Copyright (c) 1997, 1998, 1999 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997. @@ -50,13 +50,25 @@ nis_addmember (const_nis_name member, const_nis_name group) } if ((NIS_RES_NUMOBJ (res) != 1) || (__type_of (NIS_RES_OBJECT (res)) != NIS_GROUP_OBJ)) - return NIS_INVALIDOBJ; + { + nis_freeresult (res); + return NIS_INVALIDOBJ; + } NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val = realloc (NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val, (NIS_RES_OBJECT(res)->GR_data.gr_members.gr_members_len + 1) * sizeof (char *)); + if (NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val == NULL) + goto nomem_out; NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val[NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_len] = strdup (member); + if (NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val[NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_len] == NULL) + { + free (NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val); + nomem_out: + nis_freeresult (res); + return NIS_NOMEMORY; + } ++NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_len; cp = stpcpy (buf, NIS_RES_OBJECT(res)->zo_name); diff --git a/nis/nis_checkpoint.c b/nis/nis_checkpoint.c index 15bae8b..3d58472 100644 --- a/nis/nis_checkpoint.c +++ b/nis/nis_checkpoint.c @@ -1,4 +1,4 @@ -/* Copyright (c) 1997, 1998 Free Software Foundation, Inc. +/* Copyright (c) 1997, 1998, 1999 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997. @@ -39,11 +39,15 @@ nis_checkpoint(const_nis_name dirname) res2 = nis_lookup (dirname, EXPAND_NAME); if (NIS_RES_STATUS (res2) != NIS_SUCCESS) - return res2; + { + free (res); + return res2; + } /* Check if obj is really a diryectory object */ if (__type_of (NIS_RES_OBJECT (res2)) != NIS_DIRECTORY_OBJ) { + nis_freeresult (res2); nis_freeresult (res); NIS_RES_STATUS (res) = NIS_INVALIDOBJ; return res; diff --git a/nis/nis_getservlist.c b/nis/nis_getservlist.c index f88c156..a6f43f8 100644 --- a/nis/nis_getservlist.c +++ b/nis/nis_getservlist.c @@ -1,4 +1,4 @@ -/* Copyright (c) 1997, 1998 Free Software Foundation, Inc. +/* Copyright (c) 1997, 1998, 1999 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997. @@ -37,7 +37,7 @@ nis_getservlist (const_nis_name dir) nis_server *server; serv = - calloc (1, sizeof (nis_server *) * + malloc (sizeof (nis_server *) * (NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_len + 1)); if (serv == NULL) return NULL; @@ -53,10 +53,13 @@ nis_getservlist (const_nis_name dir) serv[i]->ep.ep_len = server->ep.ep_len; if (serv[i]->ep.ep_len > 0) { - unsigned long j; + unsigned long int j; serv[i]->ep.ep_val = malloc (server->ep.ep_len * sizeof (endpoint)); + if (serv[i]->ep.ep_val == NULL) + return NULL; + for (j = 0; j < serv[i]->ep.ep_len; ++j) { if (server->ep.ep_val[j].uaddr) @@ -92,6 +95,9 @@ nis_getservlist (const_nis_name dir) else serv[i]->pkey.n_bytes = NULL; } + serv[i] = NULL; + + nis_freeresult (res); } else { |