]> git.itanic.dy.fi Git - scan-pagemap/blobdiff - parse.c
Correct the usage of linked lists
[scan-pagemap] / parse.c
diff --git a/parse.c b/parse.c
index 7f62748a8468c51fbec1c1277c62b77f00829978..d13d4c70e20973f28e79f5a703dfbbd824a18353 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -91,6 +91,7 @@ static struct pageframe *alloc_pageframe(void)
                goto err;
 
        clear_pageframe(pageframe);
+       INIT_LIST_HEAD(&pageframe->ml.list);
 err:
        return pageframe;
 }
@@ -289,14 +290,9 @@ static int parse_pageframe(FILE *file, struct pageframe *pf_tree,
                         * Add a link from the physical page to this
                         * process's page map
                         */
-                       if (!match->ml) {
-                               match->ml = alloc_maplist();
-                               match->ml->map = map;
-                       } else {
-                               tmp = alloc_maplist();
-                               tmp->map = map;
-                               list_add(&tmp->list, &match->ml->list);
-                       }
+                       tmp = alloc_maplist();
+                       tmp->map = map;
+                       list_add(&tmp->list, &match->ml.list);
 
                        if (match->page_present)
                                map->pages_present++;
@@ -309,7 +305,7 @@ static int parse_pageframe(FILE *file, struct pageframe *pf_tree,
 }
 
 static int read_pageframe(int pid, int tid, struct pageframe *pageframe,
-                       struct process **process_list, struct parse_opts *opts)
+                       struct process *process_list, struct parse_opts *opts)
 {
        struct maps *maps;
        struct process *process;
@@ -320,9 +316,6 @@ static int read_pageframe(int pid, int tid, struct pageframe *pageframe,
        memset(process, 0, sizeof(*process));
        INIT_LIST_HEAD(&process->list);
 
-       if (*process_list == NULL)
-               *process_list = process;
-
        process->pid = pid;
        process->tid = tid;
 
@@ -358,7 +351,7 @@ static int read_pageframe(int pid, int tid, struct pageframe *pageframe,
                }
        }
 
-       list_add_tail(&process->list, &(*process_list)->list);
+       list_add_tail(&process->list, &process_list->list);
 
        return 1;
 free:
@@ -456,7 +449,7 @@ static int get_next_pid_by_name(DIR **dir, char *name)
 
 static int read_pageframe_with_threads(int pid,
                                struct pageframe *pageframe,
-                               struct process **process_list,
+                               struct process *process_list,
                                struct parse_opts *opts)
 {
        DIR *dir = NULL;
@@ -482,7 +475,7 @@ static int read_pageframe_with_threads(int pid,
        return count;
 }
 
-int scan_all_pids(struct pageframe *pf, struct process **process_list,
+int scan_all_pids(struct pageframe *pf, struct process *process_list,
                struct parse_opts *opts)
 {
        DIR *dir = NULL;