[v4,02/41] pstree: Implement free_pstree_item() helper

Submitted by Kirill Tkhai on May 4, 2017, 4:05 p.m.

Details

Message ID 149391391426.11711.8223960402377551679.stgit@localhost.localdomain
State New
Series "Nested pid namespaces support"
Headers show

Commit Message

Kirill Tkhai May 4, 2017, 4:05 p.m.
Helper to free pstree_item and its components.
Also, use it in collect_children() to free
dynamically allocated components.

v4: New

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/include/pstree.h |    1 +
 criu/pstree.c         |   20 ++++++++++++--------
 criu/seize.c          |    2 +-
 3 files changed, 14 insertions(+), 9 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/include/pstree.h b/criu/include/pstree.h
index 4035c6bbb..313d85666 100644
--- a/criu/include/pstree.h
+++ b/criu/include/pstree.h
@@ -85,6 +85,7 @@  static inline bool task_alive(struct pstree_item *i)
 	return is_alive_state(i->pid->state);
 }
 
+extern void free_pstree_item(struct pstree_item *item);
 extern void free_pstree(struct pstree_item *root_item);
 extern struct pstree_item *__alloc_pstree_item(bool rst, int level);
 #define alloc_pstree_item() __alloc_pstree_item(false, 1)
diff --git a/criu/pstree.c b/criu/pstree.c
index b512e43b2..b73f4405a 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -176,6 +176,16 @@  void pstree_free_cores(struct pstree_item *item)
 	}
 }
 
+void free_pstree_item(struct pstree_item *item)
+{
+	pstree_free_cores(item);
+	xfree(item->threads);
+	xfree(item->pid);
+	xfree(item->pgid);
+	xfree(item->sid);
+	xfree(item);
+}
+
 void free_pstree(struct pstree_item *root_item)
 {
 	struct pstree_item *item = root_item, *parent;
@@ -188,10 +198,7 @@  void free_pstree(struct pstree_item *root_item)
 
 		parent = item->parent;
 		list_del(&item->sibling);
-		pstree_free_cores(item);
-		xfree(item->threads);
-		xfree(item->pid);
-		xfree(item);
+		free_pstree_item(item);
 		item = parent;
 	}
 }
@@ -211,10 +218,7 @@  struct pstree_item *__alloc_pstree_item(bool rst, int level)
 		item->pgid = xmalloc(p_sz);
 		item->sid = xmalloc(p_sz);
 		if (!item->pid || !item->pgid || !item->sid) {
-			xfree(item->pid);
-			xfree(item->pgid);
-			xfree(item->sid);
-			xfree(item);
+			free_pstree_item(item);
 			return NULL;
 		}
 	} else {
diff --git a/criu/seize.c b/criu/seize.c
index 5c0c00ef3..cba0a3ecb 100644
--- a/criu/seize.c
+++ b/criu/seize.c
@@ -500,7 +500,7 @@  static int collect_children(struct pstree_item *item)
 			 * really wrong.
 			 */
 			ret = 0;
-			xfree(c);
+			free_pstree_item(c);
 			xfree(creds);
 			continue;
 		}