Properly zero memory where appropriate (bug 14401, bug 14403)

This commit is contained in:
rim
2018-05-26 23:40:11 +02:00
committed by Landry Breuil
parent fa797de140
commit 2329f243fb
6 changed files with 12 additions and 5 deletions

View File

@@ -26,7 +26,7 @@ static XtmSettings *settings;
static GtkWidget *window;
static GtkStatusIcon *status_icon;
static XtmTaskManager *task_manager;
static gboolean timeout = 0;
static gboolean timeout = FALSE;
static void
status_icon_activated (void)

View File

@@ -102,6 +102,7 @@ gboolean get_task_list (GArray *task_list)
#else
struct kinfo_proc2 p = kp[i];
#endif
bzero(&t, sizeof(t));
t.pid = p.p_pid;
t.ppid = p.p_ppid;
t.uid = p.p_uid;
@@ -116,6 +117,7 @@ gboolean get_task_list (GArray *task_list)
size = 128;
if ((args = malloc(size)) == NULL)
errx(1,"failed to allocate memory for argv structures at %zu", size);
bzero(args, size);
for (;; size *= 2) {
if ((args = realloc(args, size)) == NULL)
errx(1,"failed to allocate memory (size=%zu) for argv structures of pid %d", size, t.pid);

View File

@@ -122,6 +122,7 @@ get_task_details (kvm_t *kd, struct kinfo_proc *kp, Task *task)
char **argv;
int i;
bzero(task, sizeof(Task));
task->pid = kp->ki_pid;
task->ppid = kp->ki_ppid;
task->cpu_user = 100 * ((double)kp->ki_pctcpu / FSCALE);
@@ -213,7 +214,7 @@ get_task_list (GArray *task_list)
{
kvm_t *kd;
struct kinfo_proc *kp;
int cnt, i;
int cnt = 0, i;
Task task;
if ((kd = kvm_openfiles (_PATH_DEVNULL, _PATH_DEVNULL, NULL, O_RDONLY, NULL)) == NULL)

View File

@@ -199,6 +199,8 @@ get_task_details (guint pid, Task *task)
return FALSE;
fclose (file);
bzero(task, sizeof(Task));
/* Scanning the short process name is unreliable with scanf when it contains
* spaces, retrieve it manually and fill the buffer */
{
@@ -313,7 +315,7 @@ get_task_list (GArray *task_list)
GDir *dir;
const gchar *name;
guint pid;
Task task = { 0 };
Task task;
if ((dir = g_dir_open ("/proc", 0, NULL)) == NULL)
return FALSE;

View File

@@ -50,6 +50,7 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
static gboolean
get_task_details (guint pid, Task *task)
{
bzero(task, sizeof(Task));
g_snprintf (task->name, sizeof(task->name), "foo");
g_snprintf (task->cmdline, sizeof(task->cmdline), "foo -bar");
g_snprintf (task->uid_name, sizeof(task->uid_name), "baz");
@@ -61,7 +62,7 @@ gboolean
get_task_list (GArray *task_list)
{
guint pid = 0;
Task task = { 0 };
Task task;
//while (/* read all PIDs */)
{

View File

@@ -186,6 +186,7 @@ get_task_details (guint pid, Task *task)
return FALSE;
}
bzero(task, sizeof(Task));
task->pid = (guint)process.pr_pid;
task->ppid = (guint)process.pr_ppid;
g_strlcpy (task->name, process.pr_fname, sizeof(task->name));
@@ -210,7 +211,7 @@ get_task_list (GArray *task_list)
GDir *dir;
const gchar *name;
guint pid;
Task task = { 0 };
Task task;
if ((dir = g_dir_open ("/proc", 0, NULL)) == NULL)
return FALSE;