]> granicus.if.org Git - psmisc/commitdiff
Fixing null pointer dereference
authorJaromir Capik <jcapik@redhat.com>
Fri, 31 Jan 2014 11:45:26 +0000 (22:45 +1100)
committerCraig Small <csmall@enc.com.au>
Fri, 31 Jan 2014 11:45:26 +0000 (22:45 +1100)
Introduced with the namespaces support

References:
  https://sourceforge.net/p/psmisc/patches/32/
  https://sourceforge.net/p/psmisc/code/ci/e64b282643afecb7060c321f8401872feaf07dbb/log/?path=

Signed-off-by: Craig Small <csmall@enc.com.au>
src/pstree.c

index 2d5c05e82905a9a93ed8369681de45640a7e98bd..1cbe13124cc1d4868723e16a5de28a3fec16e394 100644 (file)
@@ -220,7 +220,12 @@ static void find_ns_and_add(struct ns_entry **root, PROC *r, enum ns_type id)
     }
 
     if (!ptr) {
-        ptr = malloc(sizeof(*ptr));
+
+        if (!(ptr = malloc(sizeof(*ptr)))) {
+            perror("malloc");
+            exit(1);
+        }
+
         memset(ptr, 0, sizeof(*ptr));
         ptr->number = r->ns[id];
         if (*root == NULL)
@@ -232,7 +237,12 @@ static void find_ns_and_add(struct ns_entry **root, PROC *r, enum ns_type id)
     /* move the child to under the namespace's umbrella */
     for (c = &ptr->children; *c; c = &(*c)->next)
         ;
-    *c = malloc(sizeof(CHILD));
+
+    if (!(*c = malloc(sizeof(CHILD)))) {
+        perror("malloc");
+        exit(1);
+    }
+
     (*c)->child = r;
     (*c)->next = NULL;