refactor the realloc code in prepend_path()

Signed-off-by: Sebastian Freundt <hroptatyr@fresse.org>