Fix the segfault by cloning input