aboutsummaryrefslogtreecommitdiff
path: root/lib/libutil/kinfo_getvmmap.c
diff options
context:
space:
mode:
authorJoe Marcus Clarke <marcus@FreeBSD.org>2008-12-19 06:47:59 +0000
committerJoe Marcus Clarke <marcus@FreeBSD.org>2008-12-19 06:47:59 +0000
commit6c3b8117adcc89a64c913a2266a744c3909c6182 (patch)
treefe6e8c1d4ff300f640bf318bf444c43c3ddc2489 /lib/libutil/kinfo_getvmmap.c
parente657c679e103e7c5e477f201bc63d6f4a86a4d48 (diff)
downloadsrc-6c3b8117adcc89a64c913a2266a744c3909c6182.tar.gz
src-6c3b8117adcc89a64c913a2266a744c3909c6182.zip
Initialize the cntp pointer to 0 prior to doing any work so that callers
don't try to iterate through garbage or NULL memory. Additionally, return NULL instead of 0 on error. Reviewed by: peter Approved by: peter
Notes
Notes: svn path=/head/; revision=186314
Diffstat (limited to 'lib/libutil/kinfo_getvmmap.c')
-rw-r--r--lib/libutil/kinfo_getvmmap.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/libutil/kinfo_getvmmap.c b/lib/libutil/kinfo_getvmmap.c
index 54361089a599..559182e40520 100644
--- a/lib/libutil/kinfo_getvmmap.c
+++ b/lib/libutil/kinfo_getvmmap.c
@@ -19,6 +19,7 @@ kinfo_getvmmap(pid_t pid, int *cntp)
char *buf, *bp, *eb;
struct kinfo_vmentry *kiv, *kp, *kv;
+ *cntp = 0;
len = 0;
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
@@ -27,15 +28,15 @@ kinfo_getvmmap(pid_t pid, int *cntp)
error = sysctl(mib, 4, NULL, &len, NULL, 0);
if (error)
- return (0);
+ return (NULL);
len = len * 4 / 3;
buf = malloc(len);
if (buf == NULL)
- return (0);
+ return (NULL);
error = sysctl(mib, 4, buf, &len, NULL, 0);
if (error) {
free(buf);
- return (0);
+ return (NULL);
}
/* Pass 1: count items */
cnt = 0;
@@ -50,7 +51,7 @@ kinfo_getvmmap(pid_t pid, int *cntp)
kiv = calloc(cnt, sizeof(*kiv));
if (kiv == NULL) {
free(buf);
- return (0);
+ return (NULL);
}
bp = buf;
eb = buf + len;