From: Andy Green Date: Thu, 30 Mar 2017 00:31:36 +0000 (+0800) Subject: lws_remove_child_from_any_parent: clear parent pointer and fix failure message X-Git-Tag: accepted/tizen/4.0/unified/20171012.191640~155 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=db64bfcefa6309a400c30acd2a0782c26382ccc4;p=platform%2Fupstream%2Flibwebsockets.git lws_remove_child_from_any_parent: clear parent pointer and fix failure message --- diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 561e61d..05b2724 100755 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -146,23 +146,27 @@ static void lws_remove_child_from_any_parent(struct lws *wsi) { struct lws **pwsi; + int seen = 0; - if (wsi->parent) { - /* detach ourselves from parent's child list */ - pwsi = &wsi->parent->child_list; - while (*pwsi) { - if (*pwsi == wsi) { - //lwsl_notice("%s: detach %p from parent %p\n", - // __func__, wsi, wsi->parent); - *pwsi = wsi->sibling_list; - break; - } - pwsi = &(*pwsi)->sibling_list; + if (!wsi->parent) + return; + + /* detach ourselves from parent's child list */ + pwsi = &wsi->parent->child_list; + while (*pwsi) { + if (*pwsi == wsi) { + lwsl_info("%s: detach %p from parent %p\n", + __func__, wsi, wsi->parent); + *pwsi = wsi->sibling_list; + seen = 1; + break; } - if (*pwsi) - lwsl_err("%s: failed to detach from parent\n", - __func__); + pwsi = &(*pwsi)->sibling_list; } + if (!seen) + lwsl_err("%s: failed to detach from parent\n", __func__); + + wsi->parent = NULL; } int