diff --git a/res/res_stasis_device_state.c b/res/res_stasis_device_state.c index 51101dd7b7..9924dd89c4 100644 --- a/res/res_stasis_device_state.c +++ b/res/res_stasis_device_state.c @@ -170,22 +170,22 @@ struct ast_json *stasis_app_device_state_to_json( struct ast_json *stasis_app_device_states_to_json(void) { struct ast_json *array = ast_json_array_create(); - RAII_VAR(struct ast_db_entry *, tree, - ast_db_gettree(DEVICE_STATE_FAMILY, NULL), ast_db_freetree); + struct ast_db_entry *tree; struct ast_db_entry *entry; + tree = ast_db_gettree(DEVICE_STATE_FAMILY, NULL); for (entry = tree; entry; entry = entry->next) { const char *name = strrchr(entry->key, '/'); + if (!ast_strlen_zero(name)) { - struct ast_str *device = ast_str_alloca(DEVICE_STATE_SIZE); - ast_str_set(&device, 0, "%s%s", - DEVICE_STATE_SCHEME_STASIS, ++name); - ast_json_array_append( - array, stasis_app_device_state_to_json( - ast_str_buffer(device), - ast_device_state(ast_str_buffer(device)))); + char device[DEVICE_STATE_SIZE]; + + snprintf(device, sizeof(device), "%s%s", DEVICE_STATE_SCHEME_STASIS, ++name); + ast_json_array_append(array, + stasis_app_device_state_to_json(device, ast_device_state(device))); } } + ast_db_freetree(tree); return array; } @@ -293,7 +293,7 @@ static void populate_cache(void) static enum ast_device_state stasis_device_state_cb(const char *data) { - char buf[DEVICE_STATE_SIZE] = ""; + char buf[DEVICE_STATE_SIZE]; ast_db_get(DEVICE_STATE_FAMILY, data, buf, sizeof(buf));