Recently we have found a piece of code that randomly crashes the Chromoting Android App:
ChromotingJniInstance::ChromotingJniInstance(...) {
// Initializations...
jni_runtime_->network_task_runner()->PostTask(
FROM_HERE,
base::Bind(&ChromotingJniInstance::ConnectToHostOnNetworkThread, this));
}
Occasionally the object will be destructed right after it is constructed, triggered by the dtor of BindState. It turns out the object is initialized with refcount 0 and raised to 1 by base::Bind and occasionally the task will be done earlier than the assignment operator that normally raises the refcount to 1, causing it to be destructed too early.
Currently there is no documentation or comment about (not) posting tasks or generally using |this| inside the constructor. I think you guys should either write some comments about this or consider this as a bug?