The do-while loop is entered: * First time: "tail_msg != NULL" (since it was set to "msg"). * Subsequent times: coming from "while" condition: ** tail_msg != NULL ** res == IOFD_SEG_ACT_HANDLE_MORE, which means iofd->pending != NULL.
Hence, always either "iofd->pending" or "tail_msg" is valid when entering the loop, and hence "msg" will also be valid.