libchromeos: Fix ASAN crash during buffet_Registration test

buffet_Registration does some http requests that rely on asynchronous
HTTP utilities from libchromeos which, in turn, use async CURL.

CURL relies on a number of callbacks that libchromeos uses to
delegate work to CURL when data is available on a connection
socket. In one instance, CURL asks libchromeos to watch a socket
for read operations and to be notified when data is available.

When we receive the notification from file descriptor watcher,
SocketPollData::OnFileCanReadWithoutBlocking() is called which
calls into CURL to MultiSocketAction. This call produces a
callback to Transport::MultiSocketCallback with CURL_POLL_REMOVE
action which we use to clean up socket user data and delete
SocketPollData structure. However the pending OnFileCanReadWithoutBlocking
is still in the call stack.

To fix the crash, do not delete SocketPollData immediately but use
MessageLoop's DeleteSoon() method which will delay destruction until
the next loop cycle.

BUG=brillo:567
TEST=USE="clang asan" emerge-link libchromeos buffet
     Deploy to device
     test_that -b link <device_ip> buffet_Registration
       -> Test passes.

Change-Id: I6bbccae64ad8fe9e18b10510763fdb20078b37d1
Reviewed-on: https://chromium-review.googlesource.com/260310
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
1 file changed