@@ -22,10 +22,11 @@ InternalServer::InternalServer() {
2222
2323static void destroyAsyncHandle (uv_handle_t *handle) {
2424 delete handle;
25+ handle = nullptr ;
2526}
2627
2728InternalServer::~InternalServer () {
28- boost::mutex::scoped_lock lock (mutex );
29+ boost::mutex::scoped_lock lock (stats_lock );
2930 if (!uv_is_closing (reinterpret_cast <uv_handle_t *>(async_stats_))) {
3031 ELOG_DEBUG (" Closing Stats handle" );
3132 uv_close (reinterpret_cast <uv_handle_t *>(async_stats_), destroyAsyncHandle);
@@ -65,7 +66,7 @@ NAN_METHOD(InternalServer::New) {
6566 InternalServer* obj = new InternalServer ();
6667 obj->me = new owt_base::InternalServer (
6768 protocol, minPort, maxPort, obj);
68- if (info.Length () > 3 ) {
69+ if (info.Length () > 3 && info[ 3 ]-> IsFunction () ) {
6970 obj->stats_callback_ = new Nan::Callback (info[3 ].As <Function>());
7071 }
7172 obj->Wrap (info.This ());
@@ -122,7 +123,7 @@ NAUV_WORK_CB(InternalServer::statsCallback) {
122123 if (!obj || !obj->me || !obj->stats_callback_ ) {
123124 return ;
124125 }
125- boost::mutex::scoped_lock lock (obj->mutex );
126+ boost::mutex::scoped_lock lock (obj->stats_lock );
126127 while (!obj->stats_messages .empty ()) {
127128 Local<Value> args[] = {
128129 Nan::New (obj->stats_messages .front ().first .c_str ()).ToLocalChecked (),
@@ -137,7 +138,7 @@ NAUV_WORK_CB(InternalServer::statsCallback) {
137138}
138139
139140void InternalServer::onConnected (const std::string& id) {
140- boost::mutex::scoped_lock lock (mutex );
141+ boost::mutex::scoped_lock lock (stats_lock );
141142 if (!async_stats_ || !stats_callback_) {
142143 return ;
143144 }
@@ -147,7 +148,7 @@ void InternalServer::onConnected(const std::string& id) {
147148}
148149
149150void InternalServer::onDisconnected (const std::string& id) {
150- boost::mutex::scoped_lock lock (mutex );
151+ boost::mutex::scoped_lock lock (stats_lock );
151152 if (!async_stats_ || !stats_callback_) {
152153 return ;
153154 }
0 commit comments