fix memory corruption error

if a recursive call happened to trigger a realloc of the packagelist,
the pkg pointer would point to invalid mem.
thus we need to fetch it again after each recursion.