]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
read_pageframe: Do not add empty entries in process list
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 15 Aug 2010 16:39:10 +0000 (19:39 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 15 Aug 2010 16:42:46 +0000 (19:42 +0300)
If reading of some of the process details fails, the process is most
likely died while we were processing its details. Thus, there is no
good to add the entry to the process list either. The entry is now
freed instead of adding the half-read entry to the list.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
parse.c

diff --git a/parse.c b/parse.c
index 850b2a1a55938961f493e0969c69839d72c725e9..3934fff77ee58b6e160756d0adeed1d1b45e506b 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -297,13 +297,12 @@ static int read_pageframe(int pid, int tid, struct pageframe *pageframe,
        process->pid = pid;
        process->tid = tid;
 
        process->pid = pid;
        process->tid = tid;
 
-       list_add_tail(&process->list, &(*process_list)->list);
 
        snprintf(path, sizeof(path), "/proc/%d/task/%d/maps", pid, tid);
        file = fopen(path, "rb");
 
        if (!file)
 
        snprintf(path, sizeof(path), "/proc/%d/task/%d/maps", pid, tid);
        file = fopen(path, "rb");
 
        if (!file)
-               return 0;
+               goto free;
 
        maps = parse_maps(file, pid, tid);
        fclose(file);
 
        maps = parse_maps(file, pid, tid);
        fclose(file);
@@ -313,23 +312,28 @@ static int read_pageframe(int pid, int tid, struct pageframe *pageframe,
        file = fopen(path, "rb");
 
        if (!file)
        file = fopen(path, "rb");
 
        if (!file)
-               return 0;
+               goto free;
 
        parse_pageframe(file, pageframe, maps, opts);
        fclose(file);
 
        if (read_cmdline(pid, tid, process->name, sizeof(process->name)))
 
        parse_pageframe(file, pageframe, maps, opts);
        fclose(file);
 
        if (read_cmdline(pid, tid, process->name, sizeof(process->name)))
-               return 1;
-
-       if (maps == NULL)
-               return 1;
+               goto free;
 
 
-       list_for_each_entry(maps, &process->maps->list, list) {
-               process->pages_present += maps->pages_present;
-               process->pages_swapped += maps->pages_swapped;
+       if (maps != NULL) {
+               list_for_each_entry(maps, &process->maps->list, list) {
+                       process->pages_present += maps->pages_present;
+                       process->pages_swapped += maps->pages_swapped;
+               }
        }
 
        }
 
+       list_add_tail(&process->list, &(*process_list)->list);
+
        return 1;
        return 1;
+free:
+       free(process);
+
+       return 0;
 }
 
 static int parse_pid(DIR **dir)
 }
 
 static int parse_pid(DIR **dir)