diff --git a/main/pbx.c b/main/pbx.c
index 1447eaf07d494e6784146f426f550ac14c31eb3e..46fc9939270695ad35bdaa149bf8cbb364f5d6b5 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -2660,7 +2660,7 @@ static int __ast_pbx_run(struct ast_channel *c)
 		if (c->cdr && ast_opt_end_cdr_before_h_exten)
 			ast_cdr_end(c->cdr);
 		set_ext_pri(c, "h", 1);
-		while ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num, &found,1))) {
+		while ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num, &found, 1)) == 0) {
 			c->priority++;
 		}
 		if (found && res) {