lpsmith / postgresql-libpq

Low-level Haskell bindings for libpq
BSD 3-Clause "New" or "Revised" License
19 stars 18 forks source link

Possibility of double free of PGconn object #26

Closed arybczak closed 9 years ago

arybczak commented 9 years ago

There seems to be a bug in threaded ghc runtime that results in execution of foreign pointer finalizers multiple times under specific circumstances (see https://ghc.haskell.org/trac/ghc/ticket/7170#comment:5). I applied a workaround to my project to prevent that from crashing the application (see https://github.com/scrive/hpqtypes/commit/cccff823a333271dc1510d5a88f250f2d7600346), but postgresql-libpq as-is is vulnerable to that. Since I plan to add more features to hpqtypes which require importing more libpq functions, I would like to avoid reinventing the wheel and use postgresql-libpq instead, but unfortunately I can't do that due to this issue. I would propose to apply the same workaround to postgresql-libpq as I did in hpqtypes.

lpsmith commented 9 years ago

postgresql-libpq already has code to work around this bug for GHC 7.0-7.4, but it was CPP'd out as it was reported as fixed in GHC 7.6.

So all we should really need to do here is change the condition on the #if.

lpsmith commented 9 years ago

Here's the code

arybczak commented 9 years ago

Oh, I missed that. It looks like it's a better solution than what I did.

lpsmith commented 9 years ago

Well, that workaround isn't mine, you can thank Joey Adams, who originally reported GHC #7170 ;-)