Index: apps/app_mixmonitor.c =================================================================== --- apps/app_mixmonitor.c (revision 38087) +++ apps/app_mixmonitor.c (working copy) @@ -81,8 +81,8 @@ struct mixmonitor { struct ast_channel_spy spy; struct ast_filestream *fs; - char *post_process; - char *name; + char post_process[1024]; + char name[AST_CHANNEL_NAME]; unsigned int flags; }; @@ -218,12 +218,18 @@ pthread_t thread; struct mixmonitor *mixmonitor; char *file_name, *ext; - char postprocess2[1024] = ""; unsigned int oflags; - size_t len; - len = sizeof(*mixmonitor) + strlen(chan->name) + 1; + /* Pre-allocate mixmonitor structure and spy */ + if (!(mixmonitor = calloc(1, sizeof(*mixmonitor)))) { + ast_log(LOG_ERROR, "Memory Error!\n"); + return; + } + /* Copy over flags and channel name */ + mixmonitor->flags = flags; + ast_copy_string(mixmonitor->name, chan->name, sizeof(mixmonitor->name)); + /* If a post process system command is given attach it to the structure */ if (!ast_strlen_zero(post_process)) { char *p1, *p2; @@ -235,26 +241,9 @@ } } - pbx_substitute_variables_helper(chan, p1, postprocess2, sizeof(postprocess2) - 1); - if (!ast_strlen_zero(postprocess2)) - len += strlen(postprocess2) + 1; + pbx_substitute_variables_helper(chan, p1, mixmonitor->post_process, sizeof(mixmonitor->post_process) - 1); } - /* Pre-allocate mixmonitor structure and spy */ - if (!(mixmonitor = calloc(1, len))) { - ast_log(LOG_ERROR, "Memory Error!\n"); - return; - } - - /* Copy over flags and channel name */ - mixmonitor->flags = flags; - mixmonitor->name = (char *) mixmonitor + sizeof(*mixmonitor); - strcpy(mixmonitor->name, chan->name); - if (!ast_strlen_zero(postprocess2)) { - mixmonitor->post_process = mixmonitor->name + strlen(mixmonitor->name) + 1; - strcpy(mixmonitor->post_process, postprocess2); - } - /* Determine creation flags and filename plus extension for filestream */ oflags = O_CREAT | O_WRONLY; oflags |= ast_test_flag(mixmonitor, MUXFLAG_APPEND) ? O_APPEND : O_TRUNC; @@ -304,7 +293,6 @@ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); ast_pthread_create(&thread, &attr, mixmonitor_thread, mixmonitor); pthread_attr_destroy(&attr); - } static int mixmonitor_exec(struct ast_channel *chan, void *data)