$OpenBSD: patch-res_res_fax_c,v 1.2 2014/04/26 11:59:51 sthen Exp $

https://issues.asterisk.org/jira/secure/attachment/46850/fax-deadlock-v2.patch-11.3.0

--- res/res_fax.c.orig	Thu Feb 27 16:03:56 2014
+++ res/res_fax.c	Wed Apr 23 22:09:43 2014
@@ -3391,10 +3391,13 @@ static struct ast_frame *fax_detect_framehook(struct a
 		switch (result) {
 		case 'f':
 		case 't':
+			if (!strcmp(ast_channel_exten(chan), "fax")) {
+				ast_debug(1, "Already in a fax extension, not redirecting\n");
+				break;
+			}
 			ast_channel_unlock(chan);
 			if (ast_exists_extension(chan, target_context, "fax", 1,
 			    S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
-				ast_channel_lock(chan);
 				ast_verb(2, "Redirecting '%s' to fax extension due to %s detection\n",
 					ast_channel_name(chan), (result == 'f') ? "CNG" : "T38");
 				pbx_builtin_setvar_helper(chan, "FAXEXTEN", ast_channel_exten(chan));
@@ -3404,10 +3407,10 @@ static struct ast_frame *fax_detect_framehook(struct a
 				ast_frfree(f);
 				f = &ast_null_frame;
 			} else {
-				ast_channel_lock(chan);
 				ast_log(LOG_NOTICE, "FAX %s detected but no fax extension in context (%s)\n",
 					(result == 'f') ? "CNG" : "T38", target_context);
 			}
+			ast_channel_lock(chan);
 		}
 		ast_framehook_detach(chan, details->faxdetect_id);
 		details->faxdetect_id = -1;
