Fixed IOT-110--Crash on destruction
authorErich Keane <erich.keane@intel.com>
Wed, 10 Dec 2014 21:43:37 +0000 (13:43 -0800)
committerErich Keane <erich.keane@intel.com>
Thu, 11 Dec 2014 21:30:22 +0000 (13:30 -0800)
commit95a02142405621a2907f05de60867d43f0d38f8e
treea3d0207673621bd5188966214d4ff2d86c3555cd
parentb97ab62aa50a692bd13f7f4cd3808fed05c5e9ea
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>
resource/csdk/stack/src/ocstack.c
resource/include/InProcClientWrapper.h
resource/src/InProcClientWrapper.cpp