* nis/nis_callback.c (__nis_create_callback): Use asprinf instead

of snprintf+strdup.  Handle OOM.
	* nis/nis_callback.c (__nis_create_callback): Allocate cb and
	cb->serv together.  Remove now obsolete free calls.
	(__nis_destroy_callback): Remove now obsolete free call.
This commit is contained in:
Ulrich Drepper 2006-05-18 17:32:19 +00:00
parent 6e2a782528
commit f90de83143
2 changed files with 18 additions and 16 deletions

View File

@ -1,3 +1,11 @@
2006-05-18 Ulrich Drepper <drepper@redhat.com>
* nis/nis_callback.c (__nis_create_callback): Use asprinf instead
of snprintf+strdup. Handle OOM.
* nis/nis_callback.c (__nis_create_callback): Allocate cb and
cb->serv together. Remove now obsolete free calls.
(__nis_destroy_callback): Remove now obsolete free call.
2006-05-18 David Woodhouse <dwmw2@infradead.org>
* sysdeps/posix/getaddrinfo.c: Add unique labels to the default

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1997, 1998, 1999, 2000, 2005 Free Software Foundation, Inc.
/* Copyright (C) 1997,1998,1999,2000,2005,2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
@ -275,15 +275,13 @@ __nis_create_callback (int (*callback) (const_nis_name, const nis_object *,
int sock = RPC_ANYSOCK;
struct sockaddr_in sin;
socklen_t len = sizeof (struct sockaddr_in);
char addr[NIS_MAXNAMELEN + 1];
unsigned short port;
cb = (struct nis_cb *) calloc (1, sizeof (struct nis_cb));
cb = (struct nis_cb *) calloc (1,
sizeof (struct nis_cb) + sizeof (nis_server));
if (__builtin_expect (cb == NULL, 0))
goto failed;
cb->serv = (nis_server *) calloc (1, sizeof (nis_server));
if (__builtin_expect (cb->serv == NULL, 0))
goto failed;
cb->serv = (nis_server *) (cb + 1);
cb->serv->name = strdup (nis_local_principal ());
if (__builtin_expect (cb->serv->name == NULL, 0))
goto failed;
@ -334,7 +332,6 @@ __nis_create_callback (int (*callback) (const_nis_name, const nis_object *,
xprt_unregister (cb->xprt);
svc_destroy (cb->xprt);
xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv);
free (cb->serv);
free (cb);
syslog (LOG_ERR, "NIS+: failed to register callback dispatcher");
return NULL;
@ -345,16 +342,17 @@ __nis_create_callback (int (*callback) (const_nis_name, const nis_object *,
xprt_unregister (cb->xprt);
svc_destroy (cb->xprt);
xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv);
free (cb->serv);
free (cb);
syslog (LOG_ERR, "NIS+: failed to read local socket info");
return NULL;
}
port = ntohs (sin.sin_port);
get_myaddress (&sin);
snprintf (addr, sizeof (addr), "%s.%d.%d", inet_ntoa (sin.sin_addr),
(port & 0xFF00) >> 8, port & 0x00FF);
cb->serv->ep.ep_val[0].uaddr = strdup (addr);
if (asprintf (&cb->serv->ep.ep_val[0].uaddr, "%s.%d.%d",
inet_ntoa (sin.sin_addr), (port & 0xFF00) >> 8, port & 0x00FF)
< 0)
goto failed;
return cb;
@ -362,10 +360,7 @@ __nis_create_callback (int (*callback) (const_nis_name, const nis_object *,
if (cb)
{
if (cb->serv)
{
xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv);
free (cb->serv);
}
xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv);
free (cb);
}
syslog (LOG_ERR, "NIS+: out of memory allocating callback");
@ -379,7 +374,6 @@ __nis_destroy_callback (struct nis_cb *cb)
svc_destroy (cb->xprt);
close (cb->sock);
xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv);
free (cb->serv);
free (cb);
return NIS_SUCCESS;