From cd8cab425ebf22104156fe2c8e9a553479feaf96 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 7 Oct 2005 23:25:36 +0000 Subject: [PATCH] proc_args fix: seems not all processes have the terminating \0 --- src/sigar_util.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/sigar_util.c b/src/sigar_util.c index 7f752eb8..d5cc2e83 100644 --- a/src/sigar_util.c +++ b/src/sigar_util.c @@ -225,12 +225,7 @@ int sigar_procfs_args_get(sigar_t *sigar, sigar_pid_t pid, if (len == 0) { break; } - if (buf) { - buf = realloc(buf, total+len); - } - else { - buf = malloc(len+1); - } + buf = realloc(buf, total+len+1); memcpy(buf+total, buffer, len); total += len; } @@ -256,7 +251,11 @@ int sigar_procfs_args_get(sigar_t *sigar, sigar_pid_t pid, memcpy(arg, ptr, alen); procargs->data[procargs->number++] = arg; - + + total -= alen; + if (total <= 0) { + break; + } ptr += alen; }