diff --git a/channels/chan_local.c b/channels/chan_local.c
index fcef1c7f1217f5dedaeb45f52f25e751b182f883..4e0316670dcff07d4e460ac1ee5e43a86dc2c513 100644
--- a/channels/chan_local.c
+++ b/channels/chan_local.c
@@ -311,11 +311,13 @@ static int local_devicestate(const char *data)
 	res = AST_DEVICE_NOT_INUSE;
 
 	it = ao2_iterator_init(locals, 0);
-	while ((lp = ao2_iterator_next(&it))) {
+	while ((lp = ao2_iterator_next(&it)) && (res == AST_DEVICE_NOT_INUSE)) {
 		if (!strcmp(exten, lp->exten) && !strcmp(context, lp->context) && lp->owner) {
-			res = AST_DEVICE_INUSE;
-			ao2_ref(lp, -1);
-			break;
+			ao2_lock(lp);
+			if (ast_test_flag(lp, LOCAL_LAUNCHED_PBX)) {
+				res = AST_DEVICE_INUSE;
+			}
+			ao2_unlock(lp);
 		}
 		ao2_ref(lp, -1);
 	}