fix glaring rwdeadlock in mod_vmd (please test i was in a hurry)

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14994 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2009-09-26 19:36:58 +00:00
parent 023c762c80
commit c38257949a
1 changed files with 17 additions and 16 deletions

View File

@ -611,20 +611,20 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_vmd_shutdown)
*/ */
SWITCH_STANDARD_API(vmd_api_main) SWITCH_STANDARD_API(vmd_api_main)
{ {
switch_core_session_t *vmd_session; switch_core_session_t *vmd_session = NULL;
switch_media_bug_t *bug; switch_media_bug_t *bug;
vmd_session_info_t *vmd_info; vmd_session_info_t *vmd_info;
switch_channel_t *channel; switch_channel_t *channel;
switch_status_t status; switch_status_t status;
int argc; int argc;
char *argv[VMD_PARAMS]; char *argv[VMD_PARAMS];
char *ccmd; char *ccmd = NULL;
char *uuid; char *uuid;
char *command; char *command;
int i; int i;
/* No command? Display usage */ /* No command? Display usage */
if (cmd == NULL) { if (switch_strlen_zero(cmd)) {
stream->write_function(stream, "-USAGE: %s\n", VMD_SYNTAX); stream->write_function(stream, "-USAGE: %s\n", VMD_SYNTAX);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
@ -638,8 +638,7 @@ SWITCH_STANDARD_API(vmd_api_main)
* display usage */ * display usage */
if (argc != VMD_PARAMS) { if (argc != VMD_PARAMS) {
stream->write_function(stream, "-USAGE: %s\n", VMD_SYNTAX); stream->write_function(stream, "-USAGE: %s\n", VMD_SYNTAX);
switch_safe_free(ccmd); goto end;
return SWITCH_STATUS_SUCCESS;
} }
uuid = argv[0]; uuid = argv[0];
@ -650,9 +649,8 @@ SWITCH_STANDARD_API(vmd_api_main)
/* If the session was not found exit */ /* If the session was not found exit */
if (vmd_session == NULL) { if (vmd_session == NULL) {
switch_safe_free(ccmd);
stream->write_function(stream, "-USAGE: %s\n", VMD_SYNTAX); stream->write_function(stream, "-USAGE: %s\n", VMD_SYNTAX);
return SWITCH_STATUS_FALSE; goto end;
} }
/* Get current channel of the session to tag the session /* Get current channel of the session to tag the session
@ -669,21 +667,18 @@ SWITCH_STANDARD_API(vmd_api_main)
switch_core_media_bug_remove(vmd_session, &bug); switch_core_media_bug_remove(vmd_session, &bug);
switch_safe_free(ccmd); switch_safe_free(ccmd);
stream->write_function(stream, "+OK\n"); stream->write_function(stream, "+OK\n");
return SWITCH_STATUS_SUCCESS; goto end;
} }
/* We have already started */ /* We have already started */
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n"); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
goto end;
switch_safe_free(ccmd);
return SWITCH_STATUS_FALSE;
} }
/* If we don't see the expected start exit */ /* If we don't see the expected start exit */
if (strcasecmp(command, "start") != 0) { if (strcasecmp(command, "start") != 0) {
switch_safe_free(ccmd);
stream->write_function(stream, "-USAGE: %s\n", VMD_SYNTAX); stream->write_function(stream, "-USAGE: %s\n", VMD_SYNTAX);
return SWITCH_STATUS_FALSE; goto end;
} }
/* Allocate memory attached to this FreeSWITCH session for /* Allocate memory attached to this FreeSWITCH session for
@ -712,9 +707,7 @@ SWITCH_STANDARD_API(vmd_api_main)
/* If adding a media bug fails exit */ /* If adding a media bug fails exit */
if (status != SWITCH_STATUS_SUCCESS) { if (status != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failure hooking to stream\n"); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failure hooking to stream\n");
goto end;
switch_safe_free(ccmd);
return SWITCH_STATUS_FALSE;
} }
/* Set the vmd tag to detect an existing vmd media bug */ /* Set the vmd tag to detect an existing vmd media bug */
@ -723,7 +716,15 @@ SWITCH_STANDARD_API(vmd_api_main)
/* Everything went according to plan! Notify the user */ /* Everything went according to plan! Notify the user */
stream->write_function(stream, "+OK\n"); stream->write_function(stream, "+OK\n");
end:
if (vmd_session) {
switch_core_session_rwunlock(vmd_session);
}
switch_safe_free(ccmd); switch_safe_free(ccmd);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }