summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2009-06-07 03:33:37 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2009-06-07 03:33:37 +0000
commitbc5fcbb23c4780ff812db39a3af75fd9f4036267 (patch)
tree7b5f56178fbec6eb0767740e0def5c2af1261bb9 /lib
parent1207fee9359b17b6793b237d0b8d36a8686df378 (diff)
fix a minor memory leak spotted by deraadt@; ok millert@ deraadt@
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/yp/yp_first.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/libc/yp/yp_first.c b/lib/libc/yp/yp_first.c
index afc8676f0b7..3e24f39ef95 100644
--- a/lib/libc/yp/yp_first.c
+++ b/lib/libc/yp/yp_first.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: yp_first.c,v 1.8 2005/08/05 13:02:16 espie Exp $ */
+/* $OpenBSD: yp_first.c,v 1.9 2009/06/07 03:33:36 schwarze Exp $ */
/*
* Copyright (c) 1992, 1993 Theo de Raadt <deraadt@theos.com>
* All rights reserved.
@@ -74,16 +74,14 @@ again:
}
if (!(r = ypprot_err(yprkv.stat))) {
*outkeylen = yprkv.key.keydat_len;
- if ((*outkey = malloc(*outkeylen + 1)) == NULL)
+ *outvallen = yprkv.val.valdat_len;
+ if ((*outkey = malloc(*outkeylen + 1)) == NULL ||
+ (*outval = malloc(*outvallen + 1)) == NULL) {
+ free(*outkey);
r = YPERR_RESRC;
- else {
+ } else {
(void)memcpy(*outkey, yprkv.key.keydat_val, *outkeylen);
(*outkey)[*outkeylen] = '\0';
- }
- *outvallen = yprkv.val.valdat_len;
- if ((*outval = malloc(*outvallen + 1)) == NULL)
- r = YPERR_RESRC;
- else {
(void)memcpy(*outval, yprkv.val.valdat_val, *outvallen);
(*outval)[*outvallen] = '\0';
}