diff options
author | jilles <jilles@FreeBSD.org> | 2012-07-15 15:22:13 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2012-07-15 15:22:13 +0000 |
commit | 7996e743fa88ff4c975f10c6c01fd006b4d4cbaf (patch) | |
tree | 5c4b33526476b8be470f298dc3d8789b16eb23e0 /bin/ps | |
parent | f0466ef5bb7d833b5033b48b53473afea74c961f (diff) | |
download | FreeBSD-src-7996e743fa88ff4c975f10c6c01fd006b4d4cbaf.zip FreeBSD-src-7996e743fa88ff4c975f10c6c01fd006b4d4cbaf.tar.gz |
ps: Fix memory leak when showing start/lstart for swapped-out process.
Spotted by: scan-build (uqs)
Diffstat (limited to 'bin/ps')
-rw-r--r-- | bin/ps/print.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/bin/ps/print.c b/bin/ps/print.c index 5c9398d..f36411e 100644 --- a/bin/ps/print.c +++ b/bin/ps/print.c @@ -387,12 +387,13 @@ started(KINFO *k, VARENT *ve __unused) size_t buflen = 100; char *buf; + if (!k->ki_valid) + return (NULL); + buf = malloc(buflen); if (buf == NULL) errx(1, "malloc failed"); - if (!k->ki_valid) - return (NULL); if (use_ampm < 0) use_ampm = (*nl_langinfo(T_FMT_AMPM) != '\0'); then = k->ki_p->ki_start.tv_sec; @@ -415,12 +416,13 @@ lstarted(KINFO *k, VARENT *ve __unused) char *buf; size_t buflen = 100; + if (!k->ki_valid) + return (NULL); + buf = malloc(buflen); if (buf == NULL) errx(1, "malloc failed"); - if (!k->ki_valid) - return (NULL); then = k->ki_p->ki_start.tv_sec; (void)strftime(buf, buflen, "%c", localtime(&then)); return (buf); |