From 7c1a9acb43fe9511577e829b4087c3c0db2eb135 Mon Sep 17 00:00:00 2001 From: Karthick Ariyaratnam Date: Tue, 30 Apr 2024 01:24:20 +0000 Subject: [PATCH] Fix memory leak issue, fix syslog-ident overriding, and added unit tests. Signed-off-by: Karthick Ariyaratnam --- src/config.c | 11 ++++++++++- tests/unit/other.tcl | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index 7df2e22b5..9cf4b864a 100644 --- a/src/config.c +++ b/src/config.c @@ -457,6 +457,7 @@ void loadServerConfigFromString(char *config) { sds *lines; sds *argv = NULL; int argc; + int syslog_ident_use_default = 1; /* Flag to decide whether or not use default for the syslog-ident config. */ reading_config_file = 1; lines = sdssplitlen(config,strlen(config),"\n",1,&totlines); @@ -512,6 +513,11 @@ void loadServerConfigFromString(char *config) { } } + /* Check whether user provided custom config for the syslog-ident */ + if (!strcasecmp(argv[0],"syslog-ident")) { + syslog_ident_use_default = 0; + } + sdsfreesplitres(argv,argc); argv = NULL; continue; @@ -629,7 +635,10 @@ void loadServerConfigFromString(char *config) { if (server.config_hz > CONFIG_MAX_HZ) server.config_hz = CONFIG_MAX_HZ; /* For backward compatibility with the Redis OSS */ - server.syslog_ident = server.extended_redis_compat ? "redis" : SERVER_NAME; + if (syslog_ident_use_default) { + zfree(server.syslog_ident); + server.syslog_ident = server.extended_redis_compat ? "redis" : SERVER_NAME; + } sdsfreesplitres(lines,totlines); reading_config_file = 0; diff --git a/tests/unit/other.tcl b/tests/unit/other.tcl index 503ee391a..b2076d7d2 100644 --- a/tests/unit/other.tcl +++ b/tests/unit/other.tcl @@ -388,6 +388,31 @@ start_server {tags {"other"}} { assert_no_match "*redis_mode:*" $info assert_match "*server_mode:*" $info } + + # When the extended redis compatibility is enabled, syslog-ident default should be "redis" by default + start_server {config "minimal.conf" overrides {extended-redis-compatibility {yes}}} { + assert_equal "redis" [lindex [r config get syslog-ident] 1] + } + + # Default for the config syslog-ident should be "valkey", where extended-redis-compatibility is disabled by default + assert_equal "valkey" [lindex [r config get syslog-ident] 1] + } + + test "Custom syslog-ident config" { + # Any user configured syslog-ident is not affected + start_server {config "minimal.conf" overrides {syslog-ident {"redis"}}} { + assert_equal "redis" [lindex [r config get syslog-ident] 1] + } + + # Any user configured syslog-ident is not affected even when the extended-redis-compatibility is enabled + start_server {config "minimal.conf" overrides {syslog-ident {"abcd"} extended-redis-compatibility yes}} { + assert_equal "abcd" [lindex [r config get syslog-ident] 1] + } + + # Any user configured syslog-ident is not affected even when it is an empty string + start_server {config "minimal.conf" overrides {syslog-ident {""}}} { + assert_equal "" [lindex [r config get syslog-ident] 1] + } } }