From: Richard Mudgett Date: Thu, 15 Jan 2015 17:35:05 +0000 (+0000) Subject: res_fax.c: Remove redundant locking. X-Git-Tag: 11.24.0-rc1~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd600f60be854fc8d2cc4408e03761318c16d698;p=thirdparty%2Fasterisk.git res_fax.c: Remove redundant locking. When FAX was developed, apparently the faxregistry.container used to be a linked list that was converted to an ao2 container. Some of the replacement ao2 container operations still had explicit lock/unlocks around them. Two off nominal code paths in res_fax.c unlock the channel even though the routine did not lock the channel and other code paths in the routine do not unlock the channel. Review: https://reviewboard.asterisk.org/r/4340/ Backported from v13 revision fa80d9658df8aff71a8975ab7d1fe477ea3f99b9. Change-Id: I59a1b95a91dac8375e0db568ddb217bcd6d7d2fa --- diff --git a/res/res_fax.c b/res/res_fax.c index f4deca4e05..5f660fe78d 100644 --- a/res/res_fax.c +++ b/res/res_fax.c @@ -1370,21 +1370,15 @@ static int generic_fax_exec(struct ast_channel *chan, struct ast_fax_session_det ast_format_copy(&orig_write_format, ast_channel_writeformat(chan)); if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR) < 0) { ast_log(LOG_ERROR, "channel '%s' failed to set write format to signed linear'.\n", ast_channel_name(chan)); - ao2_lock(faxregistry.container); - ao2_unlink(faxregistry.container, fax); - ao2_unlock(faxregistry.container); - ao2_ref(fax, -1); - ast_channel_unlock(chan); + ao2_unlink(faxregistry.container, fax); + ao2_ref(fax, -1); return -1; } ast_format_copy(&orig_read_format, ast_channel_readformat(chan)); if (ast_set_read_format_by_id(chan, AST_FORMAT_SLINEAR) < 0) { ast_log(LOG_ERROR, "channel '%s' failed to set read format to signed linear.\n", ast_channel_name(chan)); - ao2_lock(faxregistry.container); - ao2_unlink(faxregistry.container, fax); - ao2_unlock(faxregistry.container); - ao2_ref(fax, -1); - ast_channel_unlock(chan); + ao2_unlink(faxregistry.container, fax); + ao2_ref(fax, -1); return -1; } if (fax->smoother) { @@ -1560,9 +1554,7 @@ static int generic_fax_exec(struct ast_channel *chan, struct ast_fax_session_det } if (fax) { - ao2_lock(faxregistry.container); ao2_unlink(faxregistry.container, fax); - ao2_unlock(faxregistry.container); ao2_ref(fax, -1); } @@ -2508,18 +2500,14 @@ static int sendfax_exec(struct ast_channel *chan, const char *data) static void destroy_v21_sessions(struct fax_gateway *gateway) { if (gateway->chan_v21_session) { - ao2_lock(faxregistry.container); ao2_unlink(faxregistry.container, gateway->chan_v21_session); - ao2_unlock(faxregistry.container); ao2_ref(gateway->chan_v21_session, -1); gateway->chan_v21_session = NULL; } if (gateway->peer_v21_session) { - ao2_lock(faxregistry.container); ao2_unlink(faxregistry.container, gateway->peer_v21_session); - ao2_unlock(faxregistry.container); ao2_ref(gateway->peer_v21_session, -1); gateway->peer_v21_session = NULL; @@ -2537,9 +2525,7 @@ static void destroy_gateway(void *data) fax_session_release(gateway->s, gateway->token); gateway->token = NULL; - ao2_lock(faxregistry.container); ao2_unlink(faxregistry.container, gateway->s); - ao2_unlock(faxregistry.container); ao2_ref(gateway->s, -1); gateway->s = NULL;