Fix possible segfault with strdup (undefined behavior)