<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14671">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, approved
  Friendly Automation: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_musiconhold.c: Prevent crash with realtime MoH<br><br>The MoH class internal file vector is potentially being manipulated by<br>multiple threads at the same time without sufficient locking. Switch to<br>a reference counted list and operate on copies where necessary.<br><br>ASTERISK-28927 #close<br><br>Change-Id: I479c5dcf88db670956e8cac177b5826c986b0217<br>---<br>M res/res_musiconhold.c<br>1 file changed, 138 insertions(+), 32 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c</span><br><span>index 01a14b9..dd8dba5 100644</span><br><span>--- a/res/res_musiconhold.c</span><br><span>+++ b/res/res_musiconhold.c</span><br><span>@@ -171,8 +171,8 @@</span><br><span>    char announcement[256];</span><br><span>      char mode[80];</span><br><span>       char digit;</span><br><span style="color: hsl(0, 100%, 40%);">-     /*! A vector of filenames in "files" mode */</span><br><span style="color: hsl(0, 100%, 40%);">-  struct ast_vector_string files;</span><br><span style="color: hsl(120, 100%, 40%);">+       /*! An immutable vector of filenames in "files" mode */</span><br><span style="color: hsl(120, 100%, 40%);">+     struct ast_vector_string *files;</span><br><span>     unsigned int flags;</span><br><span>  /*! The format from the MOH source, not applicable to "files" mode */</span><br><span>      struct ast_format *format;</span><br><span>@@ -313,6 +313,7 @@</span><br><span> static int ast_moh_files_next(struct ast_channel *chan)</span><br><span> {</span><br><span>     struct moh_files_state *state = ast_channel_music_state(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+        struct ast_vector_string *files;</span><br><span>     int tries;</span><br><span>   size_t file_count;</span><br><span> </span><br><span>@@ -332,16 +333,21 @@</span><br><span>               state->announcement = 0;</span><br><span>  }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   file_count = AST_VECTOR_SIZE(&state->class->files);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_lock(state->class);</span><br><span style="color: hsl(120, 100%, 40%);">+    files = ao2_bump(state->class->files);</span><br><span style="color: hsl(120, 100%, 40%);">+  ao2_unlock(state->class);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        file_count = AST_VECTOR_SIZE(files);</span><br><span>         if (!file_count) {</span><br><span>           ast_log(LOG_WARNING, "No files available for class '%s'\n", state->class->name);</span><br><span style="color: hsl(120, 100%, 40%);">+              ao2_ref(files, -1);</span><br><span>          return -1;</span><br><span>   }</span><br><span> </span><br><span>        if (state->pos == 0 && ast_strlen_zero(state->save_pos_filename)) {</span><br><span>            /* First time so lets play the file. */</span><br><span>              state->save_pos = -1;</span><br><span style="color: hsl(0, 100%, 40%);">-        } else if (state->save_pos >= 0 && state->save_pos < file_count && !strcmp(AST_VECTOR_GET(&state->class->files, state->save_pos), state->save_pos_filename)) {</span><br><span style="color: hsl(120, 100%, 40%);">+    } else if (state->save_pos >= 0 && state->save_pos < file_count && !strcmp(AST_VECTOR_GET(files, state->save_pos), state->save_pos_filename)) {</span><br><span>            /* If a specific file has been saved confirm it still exists and that it is still valid */</span><br><span>           state->pos = state->save_pos;</span><br><span>          state->save_pos = -1;</span><br><span>@@ -349,7 +355,7 @@</span><br><span>               /* Get a random file and ensure we can open it */</span><br><span>            for (tries = 0; tries < 20; tries++) {</span><br><span>                    state->pos = ast_random() % file_count;</span><br><span style="color: hsl(0, 100%, 40%);">-                      if (ast_fileexists(AST_VECTOR_GET(&state->class->files, state->pos), NULL, NULL) > 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+                       if (ast_fileexists(AST_VECTOR_GET(files, state->pos), NULL, NULL) > 0) {</span><br><span>                               break;</span><br><span>                       }</span><br><span>            }</span><br><span>@@ -364,21 +370,22 @@</span><br><span>    }</span><br><span> </span><br><span>        for (tries = 0; tries < file_count; ++tries) {</span><br><span style="color: hsl(0, 100%, 40%);">-               if (ast_openstream_full(chan, AST_VECTOR_GET(&state->class->files, state->pos), ast_channel_language(chan), 1)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                if (ast_openstream_full(chan, AST_VECTOR_GET(files, state->pos), ast_channel_language(chan), 1)) {</span><br><span>                        break;</span><br><span>               }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-           ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", AST_VECTOR_GET(&state->class->files, state->pos), strerror(errno));</span><br><span style="color: hsl(120, 100%, 40%);">+             ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", AST_VECTOR_GET(files, state->pos), strerror(errno));</span><br><span>             state->pos++;</span><br><span>             state->pos %= file_count;</span><br><span>         }</span><br><span> </span><br><span>        if (tries == file_count) {</span><br><span style="color: hsl(120, 100%, 40%);">+            ao2_ref(files, -1);</span><br><span>          return -1;</span><br><span>   }</span><br><span> </span><br><span>        /* Record the pointer to the filename for position resuming later */</span><br><span style="color: hsl(0, 100%, 40%);">-    ast_copy_string(state->save_pos_filename, AST_VECTOR_GET(&state->class->files, state->pos), sizeof(state->save_pos_filename));</span><br><span style="color: hsl(120, 100%, 40%);">+     ast_copy_string(state->save_pos_filename, AST_VECTOR_GET(files, state->pos), sizeof(state->save_pos_filename));</span><br><span> </span><br><span>         ast_debug(1, "%s Opened file %d '%s'\n", ast_channel_name(chan), state->pos, state->save_pos_filename);</span><br><span> </span><br><span>@@ -395,6 +402,7 @@</span><br><span>            }</span><br><span>    }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(files, -1);</span><br><span>  return 0;</span><br><span> }</span><br><span> </span><br><span>@@ -504,7 +512,9 @@</span><br><span>             }</span><br><span>    }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   file_count = AST_VECTOR_SIZE(&class->files);</span><br><span style="color: hsl(120, 100%, 40%);">+   ao2_lock(class);</span><br><span style="color: hsl(120, 100%, 40%);">+      file_count = AST_VECTOR_SIZE(class->files);</span><br><span style="color: hsl(120, 100%, 40%);">+        ao2_unlock(class);</span><br><span> </span><br><span>       /* Resume MOH from where we left off last time or start from scratch? */</span><br><span>     if (state->save_total != file_count || strcmp(state->name, class->name) != 0) {</span><br><span>@@ -1074,8 +1084,29 @@</span><br><span>    .digit    = moh_handle_digit,</span><br><span> };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void moh_file_vector_destructor(void *obj)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_vector_string *files = obj;</span><br><span style="color: hsl(120, 100%, 40%);">+        AST_VECTOR_RESET(files, ast_free);</span><br><span style="color: hsl(120, 100%, 40%);">+    AST_VECTOR_FREE(files);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_vector_string *moh_file_vector_alloc(int initial_capacity)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_vector_string *files = ao2_alloc_options(</span><br><span style="color: hsl(120, 100%, 40%);">+          sizeof(struct ast_vector_string),</span><br><span style="color: hsl(120, 100%, 40%);">+             moh_file_vector_destructor,</span><br><span style="color: hsl(120, 100%, 40%);">+           AO2_ALLOC_OPT_LOCK_NOLOCK);</span><br><span style="color: hsl(120, 100%, 40%);">+   if (files) {</span><br><span style="color: hsl(120, 100%, 40%);">+          AST_VECTOR_INIT(files, initial_capacity);</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+     return files;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static void moh_parse_options(struct ast_variable *var, struct mohclass *mohclass)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_vector_string *playlist_entries = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>         for (; var; var = var->next) {</span><br><span>            if (!strcasecmp(var->name, "name")) {</span><br><span>                   ast_copy_string(mohclass->name, var->value, sizeof(mohclass->name));</span><br><span>@@ -1083,7 +1114,16 @@</span><br><span>                       ast_copy_string(mohclass->mode, var->value, sizeof(mohclass->mode));</span><br><span>                } else if (!strcasecmp(var->name, "entry")) {</span><br><span>                   if (ast_begins_with(var->value, "/") || ast_begins_with(var->value, "http://") || ast_begins_with(var->value, "https://")) {</span><br><span style="color: hsl(0, 100%, 40%);">-                             char *dup = ast_strdup(var->value);</span><br><span style="color: hsl(120, 100%, 40%);">+                                char *dup;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                          if (!playlist_entries) {</span><br><span style="color: hsl(120, 100%, 40%);">+                                      playlist_entries = moh_file_vector_alloc(16);</span><br><span style="color: hsl(120, 100%, 40%);">+                                 if (!playlist_entries) {</span><br><span style="color: hsl(120, 100%, 40%);">+                                              continue;</span><br><span style="color: hsl(120, 100%, 40%);">+                                     }</span><br><span style="color: hsl(120, 100%, 40%);">+                             }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                           dup = ast_strdup(var->value);</span><br><span>                             if (!dup) {</span><br><span>                                  continue;</span><br><span>                            }</span><br><span>@@ -1096,7 +1136,8 @@</span><br><span>                                                    dup);</span><br><span>                                        }</span><br><span>                            }</span><br><span style="color: hsl(0, 100%, 40%);">-                               AST_VECTOR_APPEND(&mohclass->files, dup);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                            AST_VECTOR_APPEND(playlist_entries, dup);</span><br><span>                    } else {</span><br><span>                             ast_log(LOG_ERROR, "Playlist entries must be a URL or absolute path, '%s' provided.\n", var->value);</span><br><span>                    }</span><br><span>@@ -1150,7 +1191,21 @@</span><br><span>           }</span><br><span>    }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   AST_VECTOR_COMPACT(&mohclass->files);</span><br><span style="color: hsl(120, 100%, 40%);">+  if (playlist_entries) {</span><br><span style="color: hsl(120, 100%, 40%);">+               /* If we aren't in playlist mode, drop any list we may have already built */</span><br><span style="color: hsl(120, 100%, 40%);">+              if (strcasecmp(mohclass->mode, "playlist")) {</span><br><span style="color: hsl(120, 100%, 40%);">+                    ast_log(LOG_NOTICE, "Ignoring playlist entries because we are in '%s' mode.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                             mohclass->mode);</span><br><span style="color: hsl(120, 100%, 40%);">+                   ao2_ref(playlist_entries, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+                        return;</span><br><span style="color: hsl(120, 100%, 40%);">+               }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+           AST_VECTOR_COMPACT(playlist_entries);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+               /* We don't need to lock here because we are the thread that</span><br><span style="color: hsl(120, 100%, 40%);">+               * created this mohclass and we haven't published it yet */</span><br><span style="color: hsl(120, 100%, 40%);">+               ao2_replace(mohclass->files, playlist_entries);</span><br><span style="color: hsl(120, 100%, 40%);">+    }</span><br><span> }</span><br><span> </span><br><span> static int moh_scan_files(struct mohclass *class) {</span><br><span>@@ -1162,6 +1217,7 @@</span><br><span>    char *ext;</span><br><span>   struct stat statbuf;</span><br><span>         int res;</span><br><span style="color: hsl(120, 100%, 40%);">+      struct ast_vector_string *files;</span><br><span> </span><br><span>         if (class->dir[0] != '/') {</span><br><span>               snprintf(dir_path, sizeof(dir_path), "%s/%s", ast_config_AST_DATA_DIR, class->dir);</span><br><span>@@ -1175,7 +1231,11 @@</span><br><span>            return -1;</span><br><span>   }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   AST_VECTOR_RESET(&class->files, ast_free);</span><br><span style="color: hsl(120, 100%, 40%);">+     files = moh_file_vector_alloc(16); /* 16 seems like a reasonable default */</span><br><span style="color: hsl(120, 100%, 40%);">+   if (!files) {</span><br><span style="color: hsl(120, 100%, 40%);">+         closedir(files_DIR);</span><br><span style="color: hsl(120, 100%, 40%);">+          return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+    }</span><br><span> </span><br><span>        while ((files_dirent = readdir(files_DIR))) {</span><br><span>                char *filepath_copy;</span><br><span>@@ -1204,7 +1264,7 @@</span><br><span>                         *ext = '\0';</span><br><span> </span><br><span>             /* if the file is present in multiple formats, ensure we only put it into the list once */</span><br><span style="color: hsl(0, 100%, 40%);">-              if (AST_VECTOR_GET_CMP(&class->files, &filepath[0], !strcmp)) {</span><br><span style="color: hsl(120, 100%, 40%);">+            if (AST_VECTOR_GET_CMP(files, &filepath[0], !strcmp)) {</span><br><span>                  continue;</span><br><span>            }</span><br><span> </span><br><span>@@ -1214,9 +1274,9 @@</span><br><span>                }</span><br><span> </span><br><span>                if (ast_test_flag(class, MOH_SORTALPHA)) {</span><br><span style="color: hsl(0, 100%, 40%);">-                      res = AST_VECTOR_ADD_SORTED(&class->files, filepath_copy, strcasecmp);</span><br><span style="color: hsl(120, 100%, 40%);">+                 res = AST_VECTOR_ADD_SORTED(files, filepath_copy, strcasecmp);</span><br><span>               } else {</span><br><span style="color: hsl(0, 100%, 40%);">-                        res = AST_VECTOR_APPEND(&class->files, filepath_copy);</span><br><span style="color: hsl(120, 100%, 40%);">+                 res = AST_VECTOR_APPEND(files, filepath_copy);</span><br><span>               }</span><br><span> </span><br><span>                if (res) {</span><br><span>@@ -1227,9 +1287,13 @@</span><br><span> </span><br><span>      closedir(files_DIR);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-        AST_VECTOR_COMPACT(&class->files);</span><br><span style="color: hsl(120, 100%, 40%);">+     AST_VECTOR_COMPACT(files);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-  return AST_VECTOR_SIZE(&class->files);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_lock(class);</span><br><span style="color: hsl(120, 100%, 40%);">+      ao2_replace(class->files, files);</span><br><span style="color: hsl(120, 100%, 40%);">+  ao2_unlock(class);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  return AST_VECTOR_SIZE(files);</span><br><span> }</span><br><span> </span><br><span> static int init_files_class(struct mohclass *class)</span><br><span>@@ -1355,7 +1419,13 @@</span><br><span>                      return -1;</span><br><span>           }</span><br><span>    } else if (!strcasecmp(moh->mode, "playlist")) {</span><br><span style="color: hsl(0, 100%, 40%);">-           if (!AST_VECTOR_SIZE(&moh->files)) {</span><br><span style="color: hsl(120, 100%, 40%);">+           size_t file_count;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+          ao2_lock(moh);</span><br><span style="color: hsl(120, 100%, 40%);">+                file_count = AST_VECTOR_SIZE(moh->files);</span><br><span style="color: hsl(120, 100%, 40%);">+          ao2_unlock(moh);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+            if (!file_count) {</span><br><span>                   if (unref) {</span><br><span>                                 moh = mohclass_unref(moh, "unreffing potential new moh class (no playlist entries)");</span><br><span>                      }</span><br><span>@@ -1504,7 +1574,13 @@</span><br><span>           class->format = ao2_bump(ast_format_slin);</span><br><span>                class->srcfd = -1;</span><br><span>                class->kill_delay = 100000;</span><br><span style="color: hsl(0, 100%, 40%);">-          AST_VECTOR_INIT(&class->files, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+           /* We create an empty one by default */</span><br><span style="color: hsl(120, 100%, 40%);">+               class->files = moh_file_vector_alloc(0);</span><br><span style="color: hsl(120, 100%, 40%);">+           if (!class->files) {</span><br><span style="color: hsl(120, 100%, 40%);">+                       ao2_ref(class, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+                   return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+          }</span><br><span>    }</span><br><span> </span><br><span>        return class;</span><br><span>@@ -1647,6 +1723,14 @@</span><br><span>                               mohclass->start -= respawn_time;</span><br><span> </span><br><span>                              if (!strcasecmp(mohclass->mode, "files")) {</span><br><span style="color: hsl(120, 100%, 40%);">+                                      /*</span><br><span style="color: hsl(120, 100%, 40%);">+                                     * XXX moh_scan_files returns -1 if it is unable to open the</span><br><span style="color: hsl(120, 100%, 40%);">+                                   * configured directory or there is a memory allocation</span><br><span style="color: hsl(120, 100%, 40%);">+                                        * failure. Otherwise it returns the number of files for this music</span><br><span style="color: hsl(120, 100%, 40%);">+                                    * class. This check is only checking if the number of files is zero</span><br><span style="color: hsl(120, 100%, 40%);">+                                   * and it ignores the -1 case. To avoid a behavior change we keep this</span><br><span style="color: hsl(120, 100%, 40%);">+                                         * as-is, but we should address what the 'correct' behavior should be.</span><br><span style="color: hsl(120, 100%, 40%);">+                                         */</span><br><span>                                  if (!moh_scan_files(mohclass)) {</span><br><span>                                             mohclass = mohclass_unref(mohclass, "unreffing potential mohclass (moh_scan_files failed)");</span><br><span>                                               return -1;</span><br><span>@@ -1660,7 +1744,13 @@</span><br><span>                                          ast_set_flag(mohclass, MOH_RANDOMIZE);</span><br><span>                                       }</span><br><span>                            } else if (!strcasecmp(mohclass->mode, "playlist")) {</span><br><span style="color: hsl(0, 100%, 40%);">-                                      if (!AST_VECTOR_SIZE(&mohclass->files)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                                      size_t file_count;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                                  ao2_lock(mohclass);</span><br><span style="color: hsl(120, 100%, 40%);">+                                   file_count = AST_VECTOR_SIZE(mohclass->files);</span><br><span style="color: hsl(120, 100%, 40%);">+                                     ao2_unlock(mohclass);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                                       if (!file_count) {</span><br><span>                                           mohclass = mohclass_unref(mohclass, "unreffing potential mohclass (no playlist entries)");</span><br><span>                                                 return -1;</span><br><span>                                   }</span><br><span>@@ -1723,6 +1813,13 @@</span><br><span> </span><br><span>       /* If we are using a cached realtime class with files, re-scan the files */</span><br><span>  if (!var && ast_test_flag(global_flags, MOH_CACHERTCLASSES) && mohclass->realtime && !strcasecmp(mohclass->mode, "files")) {</span><br><span style="color: hsl(120, 100%, 40%);">+          /*</span><br><span style="color: hsl(120, 100%, 40%);">+             * XXX moh_scan_files returns -1 if it is unable to open the configured directory</span><br><span style="color: hsl(120, 100%, 40%);">+              * or there is a memory allocation failure. Otherwise it returns the number of</span><br><span style="color: hsl(120, 100%, 40%);">+                 * files for this music class. This check is only checking if the number of files</span><br><span style="color: hsl(120, 100%, 40%);">+              * is zero and it ignores the -1 case. To avoid a behavior change we keep this</span><br><span style="color: hsl(120, 100%, 40%);">+                 * as-is, but we should address what the 'correct' behavior should be.</span><br><span style="color: hsl(120, 100%, 40%);">+                 */</span><br><span>          if (!moh_scan_files(mohclass)) {</span><br><span>                     mohclass = mohclass_unref(mohclass, "unreffing potential mohclass (moh_scan_files failed)");</span><br><span>                       return -1;</span><br><span>@@ -1730,7 +1827,13 @@</span><br><span>  }</span><br><span> </span><br><span>        if (!state || !state->class || strcmp(mohclass->name, state->class->name)) {</span><br><span style="color: hsl(0, 100%, 40%);">-                if (AST_VECTOR_SIZE(&mohclass->files)) {</span><br><span style="color: hsl(120, 100%, 40%);">+               size_t file_count;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+          ao2_lock(mohclass);</span><br><span style="color: hsl(120, 100%, 40%);">+           file_count = AST_VECTOR_SIZE(mohclass->files);</span><br><span style="color: hsl(120, 100%, 40%);">+             ao2_unlock(mohclass);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+               if (file_count) {</span><br><span>                    res = ast_activate_generator(chan, &moh_file_stream, mohclass);</span><br><span>          } else {</span><br><span>                     res = ast_activate_generator(chan, &mohgen, mohclass);</span><br><span>@@ -1775,6 +1878,7 @@</span><br><span>   while ((member = AST_LIST_REMOVE_HEAD(&class->members, list))) {</span><br><span>              ast_free(member);</span><br><span>    }</span><br><span style="color: hsl(120, 100%, 40%);">+     ao2_cleanup(class->files);</span><br><span>        ao2_unlock(class);</span><br><span> </span><br><span>       /* Kill the thread first, so it cannot restart the child process while the</span><br><span>@@ -1809,9 +1913,6 @@</span><br><span>           class->srcfd = -1;</span><br><span>        }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   AST_VECTOR_RESET(&class->files, ast_free);</span><br><span style="color: hsl(0, 100%, 40%);">-       AST_VECTOR_FREE(&class->files);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span>       if (class->timer) {</span><br><span>               ast_timer_close(class->timer);</span><br><span>            class->timer = NULL;</span><br><span>@@ -1993,16 +2094,21 @@</span><br><span> </span><br><span>        i = ao2_iterator_init(mohclasses, 0);</span><br><span>        for (; (class = ao2_t_iterator_next(&i, "Show files iterator")); mohclass_unref(class, "Unref iterator in moh show files")) {</span><br><span style="color: hsl(0, 100%, 40%);">-           int x;</span><br><span style="color: hsl(120, 100%, 40%);">+                struct ast_vector_string *files;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-            if (!AST_VECTOR_SIZE(&class->files)) {</span><br><span style="color: hsl(0, 100%, 40%);">-                   continue;</span><br><span style="color: hsl(120, 100%, 40%);">+             ao2_lock(class);</span><br><span style="color: hsl(120, 100%, 40%);">+              files = ao2_bump(class->files);</span><br><span style="color: hsl(120, 100%, 40%);">+            ao2_unlock(class);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+          if (AST_VECTOR_SIZE(files)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                 int x;</span><br><span style="color: hsl(120, 100%, 40%);">+                        ast_cli(a->fd, "Class: %s\n", class->name);</span><br><span style="color: hsl(120, 100%, 40%);">+                   for (x = 0; x < AST_VECTOR_SIZE(files); x++) {</span><br><span style="color: hsl(120, 100%, 40%);">+                             ast_cli(a->fd, "\tFile: %s\n", AST_VECTOR_GET(files, x));</span><br><span style="color: hsl(120, 100%, 40%);">+                        }</span><br><span>            }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-           ast_cli(a->fd, "Class: %s\n", class->name);</span><br><span style="color: hsl(0, 100%, 40%);">-             for (x = 0; x < AST_VECTOR_SIZE(&class->files); x++) {</span><br><span style="color: hsl(0, 100%, 40%);">-                        ast_cli(a->fd, "\tFile: %s\n", AST_VECTOR_GET(&class->files, x));</span><br><span style="color: hsl(0, 100%, 40%);">-           }</span><br><span style="color: hsl(120, 100%, 40%);">+             ao2_ref(files, -1);</span><br><span>  }</span><br><span>    ao2_iterator_destroy(&i);</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14671">change 14671</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/14671"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 17 </div>
<div style="display:none"> Gerrit-Change-Id: I479c5dcf88db670956e8cac177b5826c986b0217 </div>
<div style="display:none"> Gerrit-Change-Number: 14671 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>