What is the correct way to go after I found a bug in a question that I posted? Shall I delete the question, vote to close it or flag it as off-topic?
If the question has been answered, you must not edit it in a way that would invalidate the answers; that is not permitted on Code Review.
If the question is still unanswered, and the bug is easily fixed, then edit (consider temporarily deleting the question if the edit will take more than a few seconds, e.g. due to testing).
If the bug is non-trivial, then I recommend that you write an answer pointing out the bug, just as if you'd spotted it in someone else's code. If you can, show the inputs that trigger the bug. In short, you've spotted the bug because you posted it for review (regardless of the fact you're the author), so address it like any other latent bug you find when reviewing.
You shouldn't normally consider it off-topic, provided you weren't aware of the bug when posting the code for review. Spotting errors is an important part of code review; questions are off-topic only when the author already knows the code is broken, and is asking for help to fix it. If you didn't know the bug is there, you're not breaking the rules.
As others have already said, the correct answer is to delete it or edit it if there are no answers. (Or delete it, write up the edit, undelete it, and then edit it if the edit would take a long time.) But I think that it would also help to explain what happens in your other options.
Voting to close is just asking for four more people to vote to close it. While closing the question under that circumstance isn't horrible, it also means that you'd have to get votes to reopen it. Meanwhile, you can delete and undelete your question yourself. Voting to close your own question is not really something that you want to do except if it's a duplicate, which doesn't really apply on this stack.
Flagging just puts it in a queue to check if it should be closed or deleted. Or sends a message to a moderator. You don't need to tell a moderator that the question has the bug. All they could do is close or delete it. Since you can delete unanswered questions yourself, you don't need a moderator (or a queue) for that.
Deleting it is the least work for both you and everyone else. And it puts getting the question back in your control. Closing or flagging it means that you may have to ask someone else to fix it. Deleting your own question is something that you can reverse yourself.
If you delete your unanswered question and later fix the bug, you can undelete and edit the question with the new code. And that's what you should do. Replace the flawed question with a better one. Because there is a statistic that tracks the number of deleted, closed, and down-voted questions (and one question can count up to three times) that you have posted. If you have too many, your account won't be able to post questions. So the best thing is to delete the question before it gets closed or answered, fix the bug, and then undelete and edit the question.
If it gets closed or deleted, or you don't want to go through the work of fixing it, you don't need to panic. It's okay to occasionally show up on that statistic. My main point here is that you shouldn't delete it and then post a fresh question. Fix the original and get that undeleted or reopened. Then you can keep that statistic down.
If you still want your question answered, leave it open.
If you no longer want your question answered (because the bug makes the whole thing moot), then simply delete the question. There's no reason to leave a question hanging around if the author himself doesn't even want an answer.
Any solution involving "voting" or "flagging" is just making work for someone else. (I mean, so is posting on Meta, for that matter.) Leaving the question open is also making work for someone — specifically, for the people who read it and the smaller number of people who write answers. If you don't want that work done, then the way to cancel your request is simple: just delete the question.