rethab/h-gpgme

withXXX functions do not free memory if action throws exception

Closed this issue · 2 comments

All the 'withXXX' do not free the previously allocated memory if the action throws an exception.

@rethab Did you have a way to reproduce this? How did you determine that there is a memory leak?

Take a look at this:

withCtx homedir localeStr prot f = do
    ctx <- newCtx homedir localeStr prot
    res <- f ctx
    freeCtx ctx
return res

Now f is a user - supplied function. If that function throws an exception, then freeCtx is never run.