summaryrefslogtreecommitdiffstats
path: root/lib/libkvm/kvm.c
diff options
context:
space:
mode:
authordlg <dlg@openbsd.org>2015-09-04 02:58:14 +0000
committerdlg <dlg@openbsd.org>2015-09-04 02:58:14 +0000
commita6b19e380cb3a0e77626565ae1391bbf2c184038 (patch)
tree7076391325a6271fda3eb2a106e06e6a1c711a49 /lib/libkvm/kvm.c
parentadd kvm_realloc() as a private function. (diff)
downloadwireguard-openbsd-a6b19e380cb3a0e77626565ae1391bbf2c184038.tar.xz
wireguard-openbsd-a6b19e380cb3a0e77626565ae1391bbf2c184038.zip
fix a race when fetching files from the kernel. the number of files
might have increased between when we got the number of files and when we requested that number of files. now we allocate another 10ish percent on top of what the kernel says we need, and retry if that still isnt enough. while here use realloc instead of constantly going through free/malloc sequences. with input from claudio@ deraadt@ ok millert@ guenther@
Diffstat (limited to 'lib/libkvm/kvm.c')
-rw-r--r--lib/libkvm/kvm.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/libkvm/kvm.c b/lib/libkvm/kvm.c
index a261ce4ff82..f784b5f013f 100644
--- a/lib/libkvm/kvm.c
+++ b/lib/libkvm/kvm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm.c,v 1.56 2015/09/04 02:55:09 dlg Exp $ */
+/* $OpenBSD: kvm.c,v 1.57 2015/09/04 02:58:14 dlg Exp $ */
/* $NetBSD: kvm.c,v 1.43 1996/05/05 04:31:59 gwr Exp $ */
/*-
@@ -183,7 +183,7 @@ _kvm_open(kvm_t *kd, const char *uf, const char *mf, const char *sf,
kd->swfd = -1;
kd->nlfd = -1;
kd->alive = 0;
- kd->filebase = 0;
+ kd->filebase = NULL;
kd->procbase = 0;
kd->nbpg = getpagesize();
kd->swapspc = 0;
@@ -653,8 +653,7 @@ kvm_close(kvm_t *kd)
free((void *)kd->cpu_data);
if (kd->kcore_hdr != NULL)
free((void *)kd->kcore_hdr);
- if (kd->filebase != 0)
- free((void *)kd->filebase);
+ free(kd->filebase);
if (kd->procbase != 0)
free((void *)kd->procbase);
if (kd->swapspc != 0)