Don't return allocated memory in an error condition in a char **outXXX argument
(set them to the null pointer instead). Thus, code that doesn't specificallly attempt to clean up allocated memory after an error result is returned from yp_...() won't have an unexpected memory leak (i.e, most 3rd party code)
This commit is contained in:
parent
8253e6e107
commit
db4fd8d56f
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: yp_first.c,v 1.4 1997/05/20 15:25:38 lukem Exp $ */
|
||||
/* $NetBSD: yp_first.c,v 1.5 1997/05/21 06:55:25 lukem Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca>
|
||||
|
@ -32,7 +32,7 @@
|
|||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$NetBSD: yp_first.c,v 1.4 1997/05/20 15:25:38 lukem Exp $";
|
||||
static char rcsid[] = "$NetBSD: yp_first.c,v 1.5 1997/05/21 06:55:25 lukem Exp $";
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -106,6 +106,16 @@ again:
|
|||
}
|
||||
xdr_free(xdr_ypresp_key_val, (char *) &yprkv);
|
||||
_yp_unbind(ysd);
|
||||
if (r != 0) {
|
||||
if (*outkey) {
|
||||
free(*outkey);
|
||||
*outkey = NULL;
|
||||
}
|
||||
if (*outval) {
|
||||
free(*outval);
|
||||
*outval = NULL;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -176,5 +186,15 @@ again:
|
|||
}
|
||||
xdr_free(xdr_ypresp_key_val, (char *) &yprkv);
|
||||
_yp_unbind(ysd);
|
||||
if (r != 0) {
|
||||
if (*outkey) {
|
||||
free(*outkey);
|
||||
*outkey = NULL;
|
||||
}
|
||||
if (*outval) {
|
||||
free(*outval);
|
||||
*outval = NULL;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: yp_master.c,v 1.4 1997/05/20 15:25:39 lukem Exp $ */
|
||||
/* $NetBSD: yp_master.c,v 1.5 1997/05/21 06:55:25 lukem Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca>
|
||||
|
@ -32,7 +32,7 @@
|
|||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$NetBSD: yp_master.c,v 1.4 1997/05/20 15:25:39 lukem Exp $";
|
||||
static char rcsid[] = "$NetBSD: yp_master.c,v 1.5 1997/05/21 06:55:25 lukem Exp $";
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
@ -91,5 +91,11 @@ again:
|
|||
}
|
||||
xdr_free(xdr_ypresp_master, (char *) &yprm);
|
||||
_yp_unbind(ysd);
|
||||
if (r != 0) {
|
||||
if (*outname) {
|
||||
free(*outname);
|
||||
*outname = NULL;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: yp_match.c,v 1.5 1997/05/21 01:48:46 lukem Exp $ */
|
||||
/* $NetBSD: yp_match.c,v 1.6 1997/05/21 06:55:26 lukem Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993 Theo de Raadt <deraadt@fsa.ca>
|
||||
|
@ -32,7 +32,7 @@
|
|||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char rcsid[] = "$NetBSD: yp_match.c,v 1.5 1997/05/21 01:48:46 lukem Exp $";
|
||||
static char rcsid[] = "$NetBSD: yp_match.c,v 1.6 1997/05/21 06:55:26 lukem Exp $";
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -233,5 +233,11 @@ again:
|
|||
}
|
||||
xdr_free(xdr_ypresp_val, (char *) &yprv);
|
||||
_yp_unbind(ysd);
|
||||
if (r != 0) {
|
||||
if (*outval) {
|
||||
free(*outval);
|
||||
*outval = NULL;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: ypclnt.3,v 1.6 1997/05/20 15:25:41 lukem Exp $
|
||||
.\" $NetBSD: ypclnt.3,v 1.7 1997/05/21 06:55:27 lukem Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
|
@ -99,9 +99,10 @@ If necessary,
|
|||
memory will be allocated by the YP client routines using
|
||||
.Fn malloc ,
|
||||
and the result will be stored in the appropriate output value.
|
||||
If the output value after invocation of a YP client routine is not the null
|
||||
pointer, then this memory should be freed by the user if there is no
|
||||
additional need for the data stored there.
|
||||
If the invocation of a YP client routine doesn't return an error,
|
||||
and an output value is not the null pointer, then this memory
|
||||
should be freed by the user when there is no additional need for
|
||||
the data stored there.
|
||||
For
|
||||
.Pa outkey
|
||||
and
|
||||
|
|
Loading…
Reference in New Issue