1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Config: Add more utest for env config. v6.0.147 v7.0.4 (#4142)

1. don't use static variable to store the result;
2. add more UT to handle the multi value and values with whitespaces;

related to #4092 


16e569d823/trunk/src/app/srs_app_config.cpp (L71-L82)

`static SrsConfDirective* dir` removed, this static var here is to avoid
the memory leak, I add the `SrsConfDirective` instance to the `env_dirs`
directive container, which will destroy itself inside `SrsConfig`
destructor.

---------

Co-authored-by: winlin <winlinvip@gmail.com>
This commit is contained in:
Jacob Su 2024-08-15 11:12:02 +08:00 committed by GitHub
parent 38417d9ccc
commit e323215478
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 150 additions and 10 deletions

View file

@ -69,14 +69,18 @@ const char* _srs_version = "XCORE-" RTMP_SIG_SRS_SERVER;
#define SRS_OVERWRITE_BY_ENV_FLOAT_SECONDS(key) if (!srs_getenv(key).empty()) return srs_utime_t(::atof(srs_getenv(key).c_str()) * SRS_UTIME_SECONDS)
#define SRS_OVERWRITE_BY_ENV_FLOAT_MILLISECONDS(key) if (!srs_getenv(key).empty()) return srs_utime_t(::atof(srs_getenv(key).c_str()) * SRS_UTIME_MILLISECONDS)
#define SRS_OVERWRITE_BY_ENV_DIRECTIVE(key) { \
static SrsConfDirective* dir = NULL; \
SrsConfDirective* dir = env_cache_->get(key); \
if (!dir && !srs_getenv(key).empty()) { \
std::vector<string> vec = srs_string_split(srs_getenv(key), " "); \
dir = new SrsConfDirective(); \
dir->name = key; \
for (size_t i = 0; i < vec.size(); ++i) { \
dir->args.push_back(vec[i]); \
std::string value = vec[i]; \
if (!value.empty()) { \
dir->args.push_back(value); \
} \
} \
env_cache_->directives.push_back(dir); \
} \
if (dir) return dir; \
}
@ -1345,11 +1349,15 @@ SrsConfig::SrsConfig()
root = new SrsConfDirective();
root->conf_line = 0;
root->name = "root";
env_cache_ = new SrsConfDirective();
env_cache_->name = "env_cache_";
}
SrsConfig::~SrsConfig()
{
srs_freep(root);
srs_freep(env_cache_);
}
void SrsConfig::subscribe(ISrsReloadHandler* handler)