[CRIU] [PATCH 8/8] pstree: check if thread core is allocated before freeing

Dmitry Safonov dsafonov at virtuozzo.com
Fri Jul 15 12:28:47 PDT 2016


It looks like, it's possible that cores for some threads
were allocated, but not for all - allocation failed in
pstree_alloc_cores(). And after that we will dereference
NULL pointer as pstree_free_cores() doesn't check pointer:

pstree.c:28:6: warning: Access to field 'tc' results in a dereference of a null pointer (loaded from variable 'core')
        if (core->tc && core->tc->timers)
            ^~~~~~~~

Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
 criu/pstree.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/criu/pstree.c b/criu/pstree.c
index c2fa7486683a..422a7390b379 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -167,7 +167,8 @@ void pstree_free_cores(struct pstree_item *item)
 
 	if (item->core) {
 		for (i = 1; i < item->nr_threads; i++)
-			core_entry_free(item->core[i]);
+			if (item->core[i])
+				core_entry_free(item->core[i]);
 		xfree(item->core);
 		item->core = NULL;
 	}
-- 
2.9.0



More information about the CRIU mailing list