* nis/nis_findserv.c (__nis_findfastest): Improve memory handling.
* nis/nis_print_group_entry.c (nis_print_group_entry): Use alloca
instead of malloc.
* nis/nis_subr.c: Use __builtin_expect.
* nis/ypclnt.c: Likewise.
* nis/nis_getservlist.c: Likewise.
* nis/nis_creategroup.c: Likewise.
2000-04-21 Ulrich Drepper <drepper@redhat.com>
+ * nis/nis_findserv.c (__nis_findfastest): Improve memory handling.
+ * nis/nis_print_group_entry.c (nis_print_group_entry): Use alloca
+ instead of malloc.
+ * nis/nis_subr.c: Use __builtin_expect.
+ * nis/ypclnt.c: Likewise.
+ * nis/nis_getservlist.c: Likewise.
+ * nis/nis_creategroup.c: Likewise.
+
* nis/nis_callback.c (__nis_create_callback): Check result of
memory allocation. Fix memory leaks. Use __builtin_expect.
(__nis_destroy_callback): Fix memory leaks.
-/* Copyright (c) 1997, 1998, 1999 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
return NIS_BADNAME;
obj = malloc (sizeof (nis_object));
- if (obj == NULL)
+ if (__builtin_expect (obj == NULL, 0))
return NIS_NOMEMORY;
obj->zo_oid.ctime = obj->zo_oid.mtime = time (NULL);
-/* Copyright (C) 1997, 1998 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
#else
const struct timeval TIMEOUT50 = {5, 0};
const struct timeval TIMEOUT00 = {0, 0};
- struct findserv_req **pings;
+ struct findserv_req *pings;
struct sockaddr_in sin, saved_sin;
int found = -1;
u_int32_t xid_seed, xid_lookup;
pings_max = bind->server_len * 2; /* Reserve a little bit more memory
for multihomed hosts */
pings_count = 0;
- pings = malloc (sizeof (struct findserv_req *) * pings_max);
+ pings = malloc (sizeof (struct findserv_req) * pings_max);
xid_seed = (u_int32_t) (time (NULL) ^ getpid ());
+ if (__builtin_expect (pings == NULL, 0))
+ return -1;
+
memset (&sin, '\0', sizeof (sin));
sin.sin_family = AF_INET;
for (i = 0; i < bind->server_len; i++)
if (pings_count >= pings_max)
{
+ struct findserv_req *new_pings;
+
pings_max += 10;
- pings = realloc (pings, sizeof (struct findserv_req) *
- pings_max);
+ new_pings = realloc (pings, sizeof (struct findserv_req) *
+ pings_max);
+ if (__builtin_expect (new_pings == NULL, 0))
+ {
+ free (pings);
+ return -1;
+ }
+ pings = new_pings;
}
- pings[pings_count] = calloc (1, sizeof (struct findserv_req));
- memcpy ((char *) &pings[pings_count]->sin, (char *) &sin,
+ memcpy ((char *) &pings[pings_count].sin, (char *) &sin,
sizeof (sin));
memcpy ((char *)&saved_sin, (char *)&sin, sizeof(sin));
- pings[pings_count]->xid = xid_seed;
- pings[pings_count]->server_nr = i;
- pings[pings_count]->server_ep = j;
+ pings[pings_count].xid = xid_seed;
+ pings[pings_count].server_nr = i;
+ pings[pings_count].server_ep = j;
++xid_seed;
++pings_count;
}
if (clnt == NULL)
{
close (sock);
- for (i = 0; i < pings_count; ++i)
- free (pings[i]);
free (pings);
return -1;
}
for (i = 0; i < pings_count; ++i)
{
/* clntudp_call() will increment, subtract one */
- *((u_int32_t *) (cu->cu_outbuf)) = pings[i]->xid - 1;
- memcpy ((char *) &cu->cu_raddr, (char *) &pings[i]->sin,
+ *((u_int32_t *) (cu->cu_outbuf)) = pings[i].xid - 1;
+ memcpy ((char *) &cu->cu_raddr, (char *) &pings[i].sin,
sizeof (struct sockaddr_in));
/* Transmit to NULLPROC, return immediately. */
clnt_call (clnt, NULLPROC, (xdrproc_t) xdr_void, (caddr_t) foo,
xid_lookup = *((u_int32_t *) (cu->cu_inbuf));
for (i = 0; i < pings_count; i++)
{
- if (pings[i]->xid == xid_lookup)
+ if (pings[i].xid == xid_lookup)
{
- bind->server_used = pings[i]->server_nr;
- bind->current_ep = pings[i]->server_ep;
+ bind->server_used = pings[i].server_nr;
+ bind->current_ep = pings[i].server_ep;
found = 1;
}
}
clnt_destroy (clnt);
close (sock);
- for (i = 0; i < pings_count; ++i)
- free (pings[i]);
free (pings);
return found;
-/* Copyright (c) 1997, 1998, 1999 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
serv =
malloc (sizeof (nis_server *) *
(NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_len + 1));
- if (serv == NULL)
+ if (__builtin_expect (serv == NULL, 0))
return NULL;
for (i = 0; i < NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_len;
server =
&NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_val[i];
serv[i] = calloc (1, sizeof (nis_server));
+ if (__builtin_expect (serv[i] == NULL, 0))
+ return NULL;
+
if (server->name != NULL)
{
serv[i]->name = strdup (server->name);
- if (serv[i]->name == NULL)
+ if (__builtin_expect (serv[i]->name == NULL, 0))
return NULL;
}
serv[i]->ep.ep_val =
malloc (server->ep.ep_len * sizeof (endpoint));
- if (serv[i]->ep.ep_val == NULL)
+ if (__builtin_expect (serv[i]->ep.ep_val == NULL, 0))
return NULL;
for (j = 0; j < serv[i]->ep.ep_len; ++j)
serv[i]->pkey.n_len = server->pkey.n_len;
if (server->pkey.n_len > 0)
{
- serv[i]->pkey.n_bytes =
- malloc (server->pkey.n_len);
- if (serv[i]->pkey.n_bytes == NULL)
+ serv[i]->pkey.n_bytes = malloc (server->pkey.n_len);
+ if (__builtin_expect (serv[i]->pkey.n_bytes == NULL, 0))
return NULL;
memcpy (serv[i]->pkey.n_bytes, server->pkey.n_bytes,
server->pkey.n_len);
else
{
serv = malloc (sizeof (nis_server *));
- if (serv != NULL)
+ if (__builtin_expect (serv != NULL, 0))
serv[0] = NULL;
}
-/* Copyright (c) 1997, 1999 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
count = 1;
getnames = malloc ((count + 1) * sizeof (char *));
- if (getnames == NULL)
+ if (__builtin_expect (getnames == NULL, 0))
return NULL;
/* Do we have a fully qualified NIS+ name ? If yes, give it back */
{
count += 5;
getnames = realloc (getnames, (count + 1) * sizeof (char *));
- if (getnames == NULL)
+ if (__builtin_expect (getnames == NULL, 0))
return NULL;
}
tmp = malloc (strlen (cptr) + strlen (local_domain) +
strlen (name) + 2);
- if (tmp == NULL)
+ if (__builtin_expect (tmp == NULL, 0))
return NULL;
getnames[pos] = tmp;
char *p;
tmp = malloc (cplen + strlen (local_domain) + strlen (name) + 2);
- if (tmp == NULL)
+ if (__builtin_expect (tmp == NULL, 0))
return NULL;
p = __stpcpy (tmp, name);
char *p;
tmp = malloc (cplen + strlen (name) + 2);
- if (tmp == NULL)
+ if (__builtin_expect (tmp == NULL, 0))
return NULL;
p = __stpcpy (tmp, name);
{
count += 5;
getnames = realloc (getnames, (count + 1) * sizeof (char *));
- if (getnames == NULL)
+ if (__builtin_expect (getnames == NULL, 0))
return NULL;
}
getnames[pos] = tmp;
{
is_new = 1;
ysd = (dom_binding *) calloc (1, sizeof *ysd);
- if (ysd == NULL)
+ if (__builtin_expect (ysd == NULL, 0))
return YPERR_RESRC;
}
*outvallen = resp.val.valdat_len;
*outval = malloc (*outvallen + 1);
- if (*outval == NULL)
+ if (__builtin_expect (*outval == NULL, 0))
return YPERR_RESRC;
memcpy (*outval, resp.val.valdat_val, *outvallen);
(*outval)[*outvallen] = '\0';
*outkeylen = resp.key.keydat_len;
*outkey = malloc (*outkeylen + 1);
- if (*outkey == NULL)
+ if (__builtin_expect (*outkey == NULL, 0))
return YPERR_RESRC;
memcpy (*outkey, resp.key.keydat_val, *outkeylen);
(*outkey)[*outkeylen] = '\0';
*outvallen = resp.val.valdat_len;
*outval = malloc (*outvallen + 1);
- if (*outval == NULL)
+ if (__builtin_expect (*outval == NULL, 0))
return YPERR_RESRC;
memcpy (*outval, resp.val.valdat_val, *outvallen);
(*outval)[*outvallen] = '\0';
*outkeylen = resp.key.keydat_len;
*outkey = malloc (*outkeylen + 1);
- if (*outkey == NULL)
+ if (__builtin_expect (*outkey == NULL, 0))
return YPERR_RESRC;
memcpy (*outkey, resp.key.keydat_val, *outkeylen);
(*outkey)[*outkeylen] = '\0';
*outvallen = resp.val.valdat_len;
*outval = malloc (*outvallen + 1);
- if (*outval == NULL)
+ if (__builtin_expect (*outval == NULL, 0))
return YPERR_RESRC;
memcpy (*outval, resp.val.valdat_val, *outvallen);
(*outval)[*outvallen] = '\0';