There are a few slighly different things that might be going on here:
My boss has made a decision which I think is incorrect.
Tough luck: do what the boss says. Depending on how big a decision this is, make sure you've got it in writing that a) the boss said to do it, b) you disagreed but deferred to their authority. Your approach should be proportionate to the scale of risk - if it's a big decision it might be worth spending some time preparing your case or asking questions to make sure you understand what you're expected to do. Think around the problem - you might reformulate the problem above as 'When do we fix memory leaks - as soon as we find them or as late as possible, e.g. when the customer finds them?'. Other questions may arise from the decision like 'Do we document suspected leaks until we get round to fixing them? Where?'; 'How big a leak is big enough that the product is no longer viable?'.
My boss frequently takes a particular approach which I think is incorrect.
Consider: Can you measure it? If it's an issue of tail risk, probably not, but if your boss is consistently overruling your team's estimates, maybe it is. If it's safe to do so, accept the decision, but suggest measuring the outcomes. Importantly, set 'success parameters' beforehand rather than just retrospectively looking at the results and saying 'they look ok'.
Escalate: Talk to your boss' boss (in a traditional workplace structure) about how to handle the issue. Don't ask for them to overrule your boss (though they may decide to do that), leave it open for them to say your boss is right. Get a feel for what the rest of the team things before doing this. If there is an ethical component, your company may have procedures for whistleblowing - follow those.
My boss has made a decision which I think is is not only incorrect but outrageous
If a single decision, taken on its own (i.e. not as a reflection of your perception of the underlying approach) has a non-negligible probability of causing serious problems for the company, the customer, or some other interested party, then escalate as above. Examples here might include storing passwords in plain text.
I think the key question is really: How serious/minor would this problem need to be for me to decide escalation is necessary/unnecessary.
Remember that every decision comes with risks and the boss' job is likely in part to pick which risks to pay most attention to mitigating and when. Your job is to make sure they're in possession of all the information you are either asked to or are uniquely capable of producing. Some projects will start with a 50% chance of failure from the outset but with a 25% risk of being wildly successful, so from that starting point any decision will have risks of project failure - assuming these were known in advance that the boss has been put in charge to manage those risks, nobody will thank you for panicking.