diff --git a/channels/chan_unistim.c b/channels/chan_unistim.c
index bdc353844ccb6658e0d1d036b415b8105cd159a4..6762db3915a235ae7459ce336fbffbb45e18bb11 100644
--- a/channels/chan_unistim.c
+++ b/channels/chan_unistim.c
@@ -6384,10 +6384,10 @@ static struct unistim_device *build_device(const char *cat, const struct ast_var
 		}
 		d = d->next;
 	}
+	ast_mutex_unlock(&devicelock);
 	if (!(lt = ast_calloc(1, sizeof(*lt)))) {
 		return NULL;
 	}
-	ast_mutex_unlock(&devicelock);
 	if (create) {
 		if (!(d = ast_calloc(1, sizeof(*d)))) {
 			return NULL;