Jeff King <peff@xxxxxxxx> writes: > And it is complaining that we've leaked "key". But as you can see, we > always free it. The problem is that for this particular invocation we > die("missing environment variable name"), so of course we don't make it > to the free(). Normally this is OK, though. The "key" variable is still > on the stack, so the leak-checker should realize that it's still > reachable. > > But if you run this in a debugger, you'll find that under -O2 the "key" > variable has been optimized out! So LSan is producing the wrong result > due to the optimization. It doesn't know that "key" is conceptually > still reachable. Yikes. Is that related to the cause of the other patch from you, i.e. wanting to get "registers" but unable to? If they manage to get the value of the register that holds 'key', would this disappear, I wonder? > Maybe this is a known problem, but it was certainly surprising to me. > I'm not sure if we should do anything about it or not. It doesn't seem > to trigger in CI, even though I don't see us taking any steps there to > use -O0 or similar. So we can perhaps ignore it for now, and this > message can serve as a warning. But if we think LSan isn't reliable > under higher optimizations, we could perhaps teach the Makefile to > prefer -O0 when it sees SANITIZE=leak. Nice note to leave here, I agree.