winlin

merge from srs2

@@ -1288,6 +1288,7 @@ Winlin @@ -1288,6 +1288,7 @@ Winlin
1288 [bug #511]: https://github.com/ossrs/srs/issues/511 1288 [bug #511]: https://github.com/ossrs/srs/issues/511
1289 [bug #518]: https://github.com/ossrs/srs/issues/518 1289 [bug #518]: https://github.com/ossrs/srs/issues/518
1290 [bug #541]: https://github.com/ossrs/srs/issues/541 1290 [bug #541]: https://github.com/ossrs/srs/issues/541
  1291 +[bug #546]: https://github.com/ossrs/srs/issues/546
1291 [bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx 1292 [bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx
1292 1293
1293 [exo #828]: https://github.com/google/ExoPlayer/pull/828 1294 [exo #828]: https://github.com/google/ExoPlayer/pull/828
@@ -237,11 +237,13 @@ namespace internal @@ -237,11 +237,13 @@ namespace internal
237 // readly terminated now. 237 // readly terminated now.
238 really_terminated = true; 238 really_terminated = true;
239 239
240 - handler->on_thread_stop();  
241 - srs_info("thread %s cycle finished", _name);  
242 -  
243 // when thread terminated normally, also disposed. 240 // when thread terminated normally, also disposed.
  241 + // we must set to disposed before the on_thread_stop, which may free the thread.
  242 + // @see https://github.com/ossrs/srs/issues/546
244 disposed = true; 243 disposed = true;
  244 +
  245 + handler->on_thread_stop();
  246 + srs_info("thread %s cycle finished", _name);
245 } 247 }
246 248
247 void* SrsThread::thread_fun(void* arg) 249 void* SrsThread::thread_fun(void* arg)