winlin

merge from srs2

@@ -1290,6 +1290,7 @@ Winlin @@ -1290,6 +1290,7 @@ Winlin
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 #546]: https://github.com/ossrs/srs/issues/546
1292 [bug #418]: https://github.com/ossrs/srs/issues/418 1292 [bug #418]: https://github.com/ossrs/srs/issues/418
  1293 +[bug #509]: https://github.com/ossrs/srs/issues/509
1293 [bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx 1294 [bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx
1294 1295
1295 [exo #828]: https://github.com/google/ExoPlayer/pull/828 1296 [exo #828]: https://github.com/google/ExoPlayer/pull/828
@@ -1992,11 +1992,19 @@ int SrsRtmpClient::handshake() @@ -1992,11 +1992,19 @@ int SrsRtmpClient::handshake()
1992 1992
1993 srs_assert(hs_bytes); 1993 srs_assert(hs_bytes);
1994 1994
1995 - SrsComplexHandshake complex_hs;  
1996 - if ((ret = complex_hs.handshake_with_server(hs_bytes, io)) != ERROR_SUCCESS) { 1995 + // maybe st has problem when alloc object on stack, always alloc object at heap.
  1996 + // @see https://github.com/ossrs/srs/issues/509
  1997 + SrsComplexHandshake* complex_hs = new SrsComplexHandshake();
  1998 + SrsAutoFree(SrsComplexHandshake, complex_hs);
  1999 +
  2000 + if ((ret = complex_hs->handshake_with_server(hs_bytes, io)) != ERROR_SUCCESS) {
1997 if (ret == ERROR_RTMP_TRY_SIMPLE_HS) { 2001 if (ret == ERROR_RTMP_TRY_SIMPLE_HS) {
1998 - SrsSimpleHandshake simple_hs;  
1999 - if ((ret = simple_hs.handshake_with_server(hs_bytes, io)) != ERROR_SUCCESS) { 2002 + // always alloc object at heap.
  2003 + // @see https://github.com/ossrs/srs/issues/509
  2004 + SrsSimpleHandshake* simple_hs = new SrsSimpleHandshake();
  2005 + SrsAutoFree(SrsSimpleHandshake, simple_hs);
  2006 +
  2007 + if ((ret = simple_hs->handshake_with_server(hs_bytes, io)) != ERROR_SUCCESS) {
2000 return ret; 2008 return ret;
2001 } 2009 }
2002 } 2010 }