diff --git a/README.md b/README.md index 8d65b2079..5314b136f 100755 --- a/README.md +++ b/README.md @@ -1290,6 +1290,7 @@ Winlin [bug #541]: https://github.com/ossrs/srs/issues/541 [bug #546]: https://github.com/ossrs/srs/issues/546 [bug #418]: https://github.com/ossrs/srs/issues/418 +[bug #509]: https://github.com/ossrs/srs/issues/509 [bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx [exo #828]: https://github.com/google/ExoPlayer/pull/828 diff --git a/trunk/src/protocol/srs_rtmp_stack.cpp b/trunk/src/protocol/srs_rtmp_stack.cpp index 0b0e88495..0d8508af1 100644 --- a/trunk/src/protocol/srs_rtmp_stack.cpp +++ b/trunk/src/protocol/srs_rtmp_stack.cpp @@ -1992,11 +1992,19 @@ int SrsRtmpClient::handshake() srs_assert(hs_bytes); - SrsComplexHandshake complex_hs; - if ((ret = complex_hs.handshake_with_server(hs_bytes, io)) != ERROR_SUCCESS) { + // maybe st has problem when alloc object on stack, always alloc object at heap. + // @see https://github.com/ossrs/srs/issues/509 + SrsComplexHandshake* complex_hs = new SrsComplexHandshake(); + SrsAutoFree(SrsComplexHandshake, complex_hs); + + if ((ret = complex_hs->handshake_with_server(hs_bytes, io)) != ERROR_SUCCESS) { if (ret == ERROR_RTMP_TRY_SIMPLE_HS) { - SrsSimpleHandshake simple_hs; - if ((ret = simple_hs.handshake_with_server(hs_bytes, io)) != ERROR_SUCCESS) { + // always alloc object at heap. + // @see https://github.com/ossrs/srs/issues/509 + SrsSimpleHandshake* simple_hs = new SrsSimpleHandshake(); + SrsAutoFree(SrsSimpleHandshake, simple_hs); + + if ((ret = simple_hs->handshake_with_server(hs_bytes, io)) != ERROR_SUCCESS) { return ret; } }