Safe memory allocation in cli_handlers