Move the block on the error path, where the link is checked, to a place where it makes sense, to avoid accessing an unitialized link when jumping to the 'cleanup_query' label from 4 different places. The link is initialized only after those jumps happen. In addition, initilize the link when creating the object, to avoid similar errors.