Fixed IOT-110--Crash on destruction
A shared_ptr loop in callbacks for listen and a server destructor
were causing the stack to crash upon destruction of the Platform_impl.
Platform_impl would decrement the ClientWrapper shared_ptr (which would
still be >0 due to the callback having one). When the OCStop was cleaning
up its resources, it would delete the client context, decrementing the
ClientWrapper ptr completely, resulting in OCStop being called inside
itself.
This bug was fixed in a few ways (each which are important, but would
have fixed this independently).
1- Changed OCStop to protect itself from re-entrance by using a guard-bool
to return immediately if it is being called as a child.
2- ListenContext now contains a weak_ptr to the clientWrapper instead of
a shared_ptr. This makes it not destruct the clientWrapper upon callback
cleanup.
3- ClientWrapper no longer calls OCStop in the destructor when in BOTH
mode. This is done to be consistent with the OCInit call in the constructor
as well as to correctly give the ServerWrapper ownership of the Init/Process/
Stop functionality in the BOTH case.
Change-Id: I77c4646938f586e24ac6642fdeeaf82391ab082c
Signed-off-by: Erich Keane <erich.keane@intel.com>