Skip to content

Commit

Permalink
Fix memory leak issue, fix syslog-ident overriding, and added unit te…
Browse files Browse the repository at this point in the history
…sts.

Signed-off-by: Karthick Ariyaratnam <karthyuom@gmail.com>
  • Loading branch information
karthyuom committed Apr 30, 2024
1 parent 8cfdb7e commit 7c1a9ac
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/config.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/other.tcl
Expand Up @@ -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]
}
}
}

Expand Down

0 comments on commit 7c1a9ac

Please sign in to comment.