From 6271ea76cbea08c31e88a9ec41da5dc32633df1b Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Thu, 26 Nov 2026 03:45:37 -0500 Subject: [PATCH 1/3] Apply suggested fix to src/core/config.c from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --- src/core/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/config.c b/src/core/config.c index e904660ec..ae9dba194 100644 --- a/src/core/config.c +++ b/src/core/config.c @@ -2481,7 +2481,7 @@ int save_config(const config_t *config, const char *path) { * fallback, but close the stream before publishing so close errors count. */ int staged_fd = -1; if (!write_failed) { - staged_fd = dup(fileno(file)); + staged_fd = fcntl(fileno(file), F_DUPFD_CLOEXEC, 0); if (staged_fd < 0) write_failed = 1; } if (fclose(file) != 0) write_failed = 1; From ae0eff2058938e3970d278ae18c97f2ad0b8b44e Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Thu, 26 Nov 2026 03:45:39 -0500 Subject: [PATCH 2/3] Apply suggested fix to src/core/config.c from Copilot Autofix Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com> --- src/core/config.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/core/config.c b/src/core/config.c index ae9dba194..ae0b4574d 100644 --- a/src/core/config.c +++ b/src/core/config.c @@ -1503,12 +1503,6 @@ int load_stream_configs(config_t *config) { return -1; } - // Initialize all stream slots to project defaults; loaded DB rows below - // will override these defaults for populated entries. - for (size_t i = 0; i < max_streams; i++) { - init_stream_config_defaults(&config->streams[i]); - } - // Get stream count from database int count = count_stream_configs(); if (count < 0) { @@ -1517,6 +1511,12 @@ int load_stream_configs(config_t *config) { } if (count == 0) { + pthread_mutex_lock(&config_mutex); + for (size_t i = 0; i < max_streams; i++) { + init_stream_config_defaults(&config->streams[i]); + } + pthread_mutex_unlock(&config_mutex); + log_info("No stream configurations found in database"); return 0; } @@ -1541,10 +1541,20 @@ int load_stream_configs(config_t *config) { return -1; } + // Publish stream configurations under the same mutex used by snapshot readers. + pthread_mutex_lock(&config_mutex); + + // Reset all slots to defaults first; populated DB rows override these defaults. + for (size_t i = 0; i < max_streams; i++) { + init_stream_config_defaults(&config->streams[i]); + } + // Copy stream configurations to config for (int i = 0; i < loaded; i++) { memcpy(&config->streams[i], &db_streams[i], sizeof(stream_config_t)); } + + pthread_mutex_unlock(&config_mutex); free(db_streams); log_info("Loaded %d stream configurations from database", loaded); From 5dcd9303e3653e8670504624047797029b2fb43b Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Thu, 26 Nov 2026 03:50:19 -0500 Subject: [PATCH 3/3] Publish loaded streams under snapshot mutex --- src/core/config.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/core/config.c b/src/core/config.c index ae0b4574d..60242f65b 100644 --- a/src/core/config.c +++ b/src/core/config.c @@ -1490,14 +1490,20 @@ static int load_config_from_file(const char *filename, config_t *config, bool *i // Load stream configurations from database int load_stream_configs(config_t *config) { - if (!config || !config->streams) return -1; + if (!config) return -1; + + pthread_mutex_lock(&mp4_faststart_mutex); + stream_config_t *initial_streams = config->streams; + int initial_max_streams = config->max_streams; + pthread_mutex_unlock(&mp4_faststart_mutex); + if (!initial_streams) return -1; - if (config->max_streams <= 0 || config->max_streams > MAX_STREAMS) { - log_error("load_stream_configs: invalid max_streams value (%d)", config->max_streams); + if (initial_max_streams <= 0 || initial_max_streams > MAX_STREAMS) { + log_error("load_stream_configs: invalid max_streams value (%d)", initial_max_streams); return -1; } - size_t max_streams = (size_t)config->max_streams; + size_t max_streams = (size_t)initial_max_streams; if (max_streams > SIZE_MAX / sizeof(stream_config_t)) { log_error("load_stream_configs: max_streams causes size overflow"); return -1; @@ -1511,11 +1517,15 @@ int load_stream_configs(config_t *config) { } if (count == 0) { - pthread_mutex_lock(&config_mutex); + pthread_mutex_lock(&mp4_faststart_mutex); + if (config->streams != initial_streams || config->max_streams != initial_max_streams) { + pthread_mutex_unlock(&mp4_faststart_mutex); + return -1; + } for (size_t i = 0; i < max_streams; i++) { init_stream_config_defaults(&config->streams[i]); } - pthread_mutex_unlock(&config_mutex); + pthread_mutex_unlock(&mp4_faststart_mutex); log_info("No stream configurations found in database"); return 0; @@ -1542,7 +1552,12 @@ int load_stream_configs(config_t *config) { } // Publish stream configurations under the same mutex used by snapshot readers. - pthread_mutex_lock(&config_mutex); + pthread_mutex_lock(&mp4_faststart_mutex); + if (config->streams != initial_streams || config->max_streams != initial_max_streams) { + pthread_mutex_unlock(&mp4_faststart_mutex); + free(db_streams); + return -1; + } // Reset all slots to defaults first; populated DB rows override these defaults. for (size_t i = 0; i < max_streams; i++) { @@ -1554,7 +1569,7 @@ int load_stream_configs(config_t *config) { memcpy(&config->streams[i], &db_streams[i], sizeof(stream_config_t)); } - pthread_mutex_unlock(&config_mutex); + pthread_mutex_unlock(&mp4_faststart_mutex); free(db_streams); log_info("Loaded %d stream configurations from database", loaded);