summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2014-11-04 17:17:05 +0000
committermillert <millert@openbsd.org>2014-11-04 17:17:05 +0000
commitaeb9def4eee3b10083cf83330edc6b2cb63aeaca (patch)
tree5d233831644bf6d4f1005dcf3b2608b7ae34cf11
parentbounds check, apply from upstream devel/libmagic (diff)
downloadwireguard-openbsd-aeb9def4eee3b10083cf83330edc6b2cb63aeaca.tar.xz
wireguard-openbsd-aeb9def4eee3b10083cf83330edc6b2cb63aeaca.zip
Fix memory leak on reallocarray() failure introduced by conversion
from calloc().
-rw-r--r--lib/libc/rpc/svc_run.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/libc/rpc/svc_run.c b/lib/libc/rpc/svc_run.c
index 84099982656..2be4f25745d 100644
--- a/lib/libc/rpc/svc_run.c
+++ b/lib/libc/rpc/svc_run.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: svc_run.c,v 1.22 2014/10/22 23:10:30 millert Exp $ */
+/* $OpenBSD: svc_run.c,v 1.23 2014/11/04 17:17:05 millert Exp $ */
/*
* Copyright (c) 2010, Oracle America, Inc.
@@ -45,13 +45,14 @@
void
svc_run(void)
{
- struct pollfd *pfd = NULL;
+ struct pollfd *pfd = NULL, *newp;
int nready, saved_max_pollfd = 0;
for (;;) {
if (svc_max_pollfd > saved_max_pollfd) {
- pfd = reallocarray(pfd, svc_max_pollfd, sizeof(*pfd));
- if (pfd == NULL) {
+ newp = reallocarray(pfd, svc_max_pollfd, sizeof(*pfd));
+ if (newp == NULL) {
+ free(pfd);
perror("svc_run"); /* XXX */
return; /* XXX */
}
@@ -68,6 +69,7 @@ svc_run(void)
free(pfd);
return; /* XXX */
case 0:
+ /* should not happen */
continue;
default:
svc_getreq_poll(pfd, nready);