From e22fb28f96980099e5ffd4715acfa55bb0735a4b Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Mon, 11 Sep 2023 01:49:39 -0400 Subject: [PATCH] safeguards on file name --- src/transcription-filter.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/transcription-filter.cpp b/src/transcription-filter.cpp index df98c6e..0b16f64 100644 --- a/src/transcription-filter.cpp +++ b/src/transcription-filter.cpp @@ -177,7 +177,7 @@ void acquire_weak_text_source_ref(struct transcription_filter_data *gf) void set_text_callback(struct transcription_filter_data *gf, const std::string &str) { - if (gf->output_file_path != "") { + if (gf->output_file_path != "" && !gf->text_source_name) { // Write to file, do not append std::ofstream output_file(gf->output_file_path, std::ios::out | std::ios::trunc); output_file << str; @@ -226,7 +226,8 @@ void transcription_filter_update(void *data, obs_data_t *s) const char *new_text_source_name = obs_data_get_string(s, "subtitle_sources"); obs_weak_source_t *old_weak_text_source = NULL; - if (strcmp(new_text_source_name, "none") == 0 || + if (new_text_source_name == nullptr || + strcmp(new_text_source_name, "none") == 0 || strcmp(new_text_source_name, "(null)") == 0 || strcmp(new_text_source_name, "text_file") == 0 || strlen(new_text_source_name) == 0) { // new selected text source is not valid, release the old one @@ -266,6 +267,11 @@ void transcription_filter_update(void *data, obs_data_t *s) old_weak_text_source = gf->text_source; gf->text_source = nullptr; } + if (gf->text_source_name) { + // free the old text source name + bfree(gf->text_source_name); + gf->text_source_name = nullptr; + } gf->text_source_name = bstrdup(new_text_source_name); } } @@ -413,6 +419,7 @@ void *transcription_filter_create(obs_data_t *settings, obs_source_t *filter) gf->text_source_mutex = new std::mutex(); gf->text_source = nullptr; gf->text_source_name = bstrdup(obs_data_get_string(settings, "subtitle_sources")); + gf->output_file_path = std::string(""); obs_log(gf->log_level, "transcription_filter: run update"); // get the settings updated on the filter data struct