From db5e43967c77d32f900f22be97a175709a1db12a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haibo=20Chen=28=E9=99=88=E6=B5=B7=E5=8D=9A=29?= <495810242@qq.com> Date: Tue, 12 Aug 2025 21:13:59 +0800 Subject: [PATCH] Valgrind: Return error for unsupported check=new on Valgrind < 3.21. v7.0.52 (#4301) ## Problem The `valgrind?check=new` API parameter uses `VALGRIND_DO_NEW_LEAK_CHECK` which is only available in Valgrind 3.21+. On older versions like CentOS's default Valgrind 3.16, this causes undefined behavior since the macro is not defined. ## Solution - Check for `VALGRIND_DO_NEW_LEAK_CHECK` availability before processing the request - Return `ERROR_NOT_SUPPORTED` with version information when unsupported - Move the version check before thread creation to avoid unnecessary resource allocation ## Changes - Early validation of `check=new` parameter compatibility - Proper error response with current Valgrind version details - Prevents undefined behavior on older Valgrind installations Fixes compatibility issues with older Valgrind versions commonly found in enterprise Linux distributions. --------- Co-authored-by: Jacob Su Co-authored-by: winlin Co-authored-by: OSSRS-AI --- trunk/doc/CHANGELOG.md | 1 + trunk/src/app/srs_app_http_api.cpp | 23 ++++++++++++++++------- trunk/src/kernel/srs_kernel_error.hpp | 3 ++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index bfb95dd41..36e815e91 100644 --- a/trunk/doc/CHANGELOG.md +++ b/trunk/doc/CHANGELOG.md @@ -7,6 +7,7 @@ The changelog for SRS. ## SRS 7.0 Changelog +* v7.0, 2025-08-12, Merge [#4301](https://github.com/ossrs/srs/pull/4301): Valgrind: Return error for unsupported check=new on Valgrind < 3.21. v7.0.52 (#4301) * v7.0, 2025-08-12, Merge [#4431](https://github.com/ossrs/srs/pull/4431): fix srt cmake 4.x compiling error. v7.0.52 (#4431) * v7.0, 2025-08-11, Merge [#4433](https://github.com/ossrs/srs/pull/4433): Use clang format. v7.0.52 (#4433) * v7.0, 2025-08-11, Merge [#4159](https://github.com/ossrs/srs/pull/4159): Feature: Support HLS with fmp4 segment for HEVC/LLHLS. v7.0.51 (#4159) diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index e2b1382ca..45a111694 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -1118,13 +1118,6 @@ srs_error_t SrsGoApiValgrind::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMess { srs_error_t err = srs_success; - if (!trd_) { - trd_ = new SrsSTCoroutine("valgrind", this, _srs_context->get_id()); - if ((err = trd_->start()) != srs_success) { - return srs_error_wrap(err, "start"); - } - } - string check = r->query_get("check"); srs_trace("query check=%s", check.c_str()); @@ -1134,6 +1127,22 @@ srs_error_t SrsGoApiValgrind::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMess check = "full"; } + // Check if 'new' leak check is supported in current Valgrind version + if (check == "new") { +#if !defined(VALGRIND_DO_NEW_LEAK_CHECK) + return srs_error_new(ERROR_NOT_SUPPORTED, + "valgrind?check=new requires Valgrind 3.21+, current version is %d.%d", + __VALGRIND_MAJOR__, __VALGRIND_MINOR__); +#endif + } + + if (!trd_) { + trd_ = new SrsSTCoroutine("valgrind", this, _srs_context->get_id()); + if ((err = trd_->start()) != srs_success) { + return srs_error_wrap(err, "start"); + } + } + // By default, response the json style response. SrsUniquePtr obj(SrsJsonAny::object()); diff --git a/trunk/src/kernel/srs_kernel_error.hpp b/trunk/src/kernel/srs_kernel_error.hpp index dee33553e..bff4a6edd 100644 --- a/trunk/src/kernel/srs_kernel_error.hpp +++ b/trunk/src/kernel/srs_kernel_error.hpp @@ -109,7 +109,8 @@ XX(ERROR_SYSTEM_FILE_SETVBUF, 1096, "FileSetVBuf", "Failed to set file vbuf") \ XX(ERROR_NO_SOURCE, 1097, "NoSource", "No source found") \ XX(ERROR_STREAM_DISPOSING, 1098, "StreamDisposing", "Stream is disposing") \ - XX(ERROR_NOT_IMPLEMENTED, 1099, "NotImplemented", "Feature is not implemented") + XX(ERROR_NOT_IMPLEMENTED, 1099, "NotImplemented", "Feature is not implemented") \ + XX(ERROR_NOT_SUPPORTED, 1100, "NotSupported", "Feature is not supported") /**************************************************/ /* RTMP protocol error. */