2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 06:15:24 +00:00

pstree: Implement free_pstree_item() helper

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>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
Kirill Tkhai
2017-05-05 19:12:24 +03:00
committed by Andrei Vagin
parent 79c3e2618e
commit 0904d50e67
3 changed files with 14 additions and 9 deletions

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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;
}