From 5d4736e04343120bd959fe79e33848eb0ceedd06 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 30 Jul 2004 02:02:41 +0000 Subject: [PATCH] proc_modules refactor to prevent possible phandle leaks --- src/os/solaris/solaris_sigar.c | 37 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/os/solaris/solaris_sigar.c b/src/os/solaris/solaris_sigar.c index 80f856e3..a4a45e25 100644 --- a/src/os/solaris/solaris_sigar.c +++ b/src/os/solaris/solaris_sigar.c @@ -790,24 +790,6 @@ static int sigar_pgrab_modules(sigar_t *sigar, sigar_pid_t pid, struct stat statbuf; char buffer[BUFSIZ]; - if ((pstatus = sigar_init_libproc(sigar)) != SIGAR_OK) { - return pstatus; - } - - if (!(phandle = sigar->pgrab(pid, 0x01, &pstatus))) { - switch (pstatus) { - case G_NOPROC: - return ESRCH; - case G_PERM: - return EACCES; - default: - sigar_log_printf(sigar, SIGAR_LOG_ERROR, - "[%s] Pgrab error=%d", - SIGAR_FUNC, pstatus); - return ENOTSUP; /*XXX*/ - } - } - (void)SIGAR_PROC_FILENAME(buffer, pid, "/xmap"); if ((fd = open(buffer, O_RDONLY)) < 0) { @@ -827,12 +809,31 @@ static int sigar_pgrab_modules(sigar_t *sigar, sigar_pid_t pid, SIGAR_FUNC, pid, map_size); } + if ((pstatus = sigar_init_libproc(sigar)) != SIGAR_OK) { + return pstatus; + } + + if (!(phandle = sigar->pgrab(pid, 0x01, &pstatus))) { + switch (pstatus) { + case G_NOPROC: + return ESRCH; + case G_PERM: + return EACCES; + default: + sigar_log_printf(sigar, SIGAR_LOG_ERROR, + "[%s] Pgrab error=%d", + SIGAR_FUNC, pstatus); + return ENOTSUP; /*XXX*/ + } + } + for (nread=0; nread sizeof(xmaps) ? sizeof(xmaps) : map_size; int total = wanted / sizeof(prxmap_t); if (pread(fd, xmaps, wanted, nread) != wanted) { close(fd); + sigar->pfree(phandle); return errno; }