summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJaromir Capik <jcapik@redhat.com>2014-01-31 22:45:26 +1100
committerCraig Small <csmall@enc.com.au>2014-01-31 22:45:26 +1100
commit4b50aac325fb56c3188b12fadcca1dec1adba17c (patch)
tree791b6d027b51c35fc82b8d2a63dc7aa94ca95561 /src
parente64b282643afecb7060c321f8401872feaf07dbb (diff)
Fixing null pointer dereference
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>
Diffstat (limited to 'src')
-rw-r--r--src/pstree.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/pstree.c b/src/pstree.c
index 2d5c05e..1cbe131 100644
--- a/src/pstree.c
+++ b/src/pstree.c
@@ -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;