summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 77311ae)
raw | patch | inline | side by side (parent: 77311ae)
author | Cosmin Ioiart <cioiart+dev@gmail.com> | |
Wed, 7 Mar 2012 11:33:12 +0000 (12:33 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Sun, 23 Sep 2012 10:39:31 +0000 (12:39 +0200) |
Replaced "free" with "sfree" for memory deallocation.
Added memset(...) to initialized newly allocated memory
Removed buffer "termination".
Added memset(...) to initialized newly allocated memory
Removed buffer "termination".
src/processes.c | patch | blob | history |
diff --git a/src/processes.c b/src/processes.c
index 61955f829de042073c21a9185ca39085805730f6..20842518a4e4f5f815ac9afc2f0d898b6aeed3e9 100644 (file)
--- a/src/processes.c
+++ b/src/processes.c
static char *ps_get_cmdline(pid_t pid)
{
char f_psinfo[64];
+ char cmdline[80];
char *buffer = NULL;
psinfo_t *myInfo;
snprintf(f_psinfo, sizeof (f_psinfo), "/proc/%i/psinfo", pid);
- buffer = malloc(sizeof (psinfo_t));
+ buffer = (char *)malloc(sizeof (psinfo_t));
+ memset(buffer, 0, sizeof(psinfo_t));
read_file_contents(f_psinfo, buffer, sizeof (psinfo_t));
- buffer[sizeof (psinfo_t)] = 0;
myInfo = (psinfo_t *) buffer;
- sstrncpy(buffer, myInfo->pr_psargs, sizeof (myInfo->pr_psargs));
+ sstrncpy(cmdline, myInfo->pr_psargs, sizeof (myInfo->pr_psargs));
- free(myInfo);
- return strtok(buffer, " ");
+ sfree(myInfo);
+ return strtok(cmdline, " ");
}
/*
buffer = malloc(sizeof (pstatus_t));
+ memset(buffer, 0, sizeof (pstatus_t));
read_file_contents(filename, buffer, sizeof (pstatus_t));
myStatus = (pstatus_t *) buffer;
buffer = malloc(sizeof (psinfo_t));
+ memset(buffer, 0, sizeof(psinfo_t));
read_file_contents(f_psinfo, buffer, sizeof (psinfo_t));
- buffer[sizeof (psinfo_t)] = 0;
myInfo = (psinfo_t *) buffer;
buffer = malloc(sizeof (prusage_t));
+ memset(buffer, 0, sizeof(prusage_t));
read_file_contents(f_usage, buffer, sizeof (prusage_t));
myUsage = (prusage_t *) buffer;
else if (myStatus->pr_flags & PR_ORPHAN)
*state = (char) 'O';
- free(myStatus);
- free(myInfo);
- free(myUsage);
+ sfree(myStatus);
+ sfree(myInfo);
+ sfree(myUsage);
return (0);
}