diff --git a/res/res_fax.c b/res/res_fax.c
index cae96603fa9490d1f377c6b2743ade4d32dfd74d..0aedd2decf435ee27f9a0009007e45c3c30b971b 100644
--- a/res/res_fax.c
+++ b/res/res_fax.c
@@ -901,7 +901,7 @@ static int generic_fax_exec(struct ast_channel *chan, struct ast_fax_session_det
 
 	/* handle frames for the session */
 	ms = 1000;
-	while ((ms > -1) && (timeout > 0)) {
+	while ((res > -1) && (ms > -1) && (timeout > 0)) {
 		struct ast_channel *ready_chan;
 		int ofd, exception;