set_current_prefix() searches for the current program executable file in $PATH, and it can fail and return 0. In that case, relocatep will probably segfault at the location marked below: > char *relocated_path = new char[curr_prefix_len + relative_path_len + 1]; > strcpy(relocated_path, curr_prefix); ^^^^^^^^^^^