diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2015-09-04 02:58:15 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2015-09-04 02:58:15 +0000 |
commit | 257c2732903c8dc2a2e5edc5013da40f3b3ad8fb (patch) | |
tree | 1d6d91ceec375c0ca2e802229011625b39511007 /lib/libkvm/kvm.c | |
parent | f9d2816e89126e3eed53e66635fa41b8b1c74efa (diff) |
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.c | 7 |
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) |