[9.18] Don't use an uninitialized link on an error path

Backport of !8343 (merged).

Closes #4331 (closed)

Merge request reports