diff options
author | Rob Landley <rob@landley.net> | 2017-08-31 16:50:27 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2017-08-31 16:50:27 -0500 |
commit | bebf14cc298eb41d8e5c245e3800aea69ecca08c (patch) | |
tree | 05d7c9dc75befb23cc954e6f39d154c8025eedc2 /toys | |
parent | 709a44246456a49c06d73dfbe84daa5b4ba5fec5 (diff) | |
download | toybox-bebf14cc298eb41d8e5c245e3800aea69ecca08c.tar.gz |
Another try at fixing the ps segfault resulting from /proc entries vanishing
out from under us due to asyncronous process exit.
The directory we're traversing vanishing can result in DIRTREE_ABORTVAL
being returned, which we turn into a NUL entry, but then we were trying to
look at that null entry's children. Oops.
Diffstat (limited to 'toys')
-rw-r--r-- | toys/posix/ps.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/toys/posix/ps.c b/toys/posix/ps.c index a0dc53f5..aef2a7f7 100644 --- a/toys/posix/ps.c +++ b/toys/posix/ps.c @@ -915,15 +915,16 @@ static int get_threads(struct dirtree *new) // Save or display if (!TT.show_process) return DIRTREE_SAVE; TT.show_process((void *)new->extra); - dt = new->child; - new->child = 0; - while (dt->child) { - new = dt->child->next; - TT.show_process((void *)dt->child->extra); - free(dt->child); - dt->child = new; + if ((dt = new->child)) { + new->child = 0; + while (dt->child) { + new = dt->child->next; + TT.show_process((void *)dt->child->extra); + free(dt->child); + dt->child = new; + } + free(dt); } - free(dt); return 0; } |