From 2de813324245f43e0177549dfb2820f06189964b Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Sun, 19 Apr 2020 11:27:49 -0400 Subject: base: Use keepAlive# in withForeignPtr --- libraries/base/GHC/ForeignPtr.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/base/GHC/ForeignPtr.hs b/libraries/base/GHC/ForeignPtr.hs index 79d1614529..774dafdf70 100644 --- a/libraries/base/GHC/ForeignPtr.hs +++ b/libraries/base/GHC/ForeignPtr.hs @@ -526,7 +526,9 @@ withForeignPtr :: ForeignPtr a -> (Ptr a -> IO b) -> IO b -- or from the object pointed to by the -- 'ForeignPtr', using the operations from the -- 'Storable' class. -withForeignPtr = unsafeWithForeignPtr +withForeignPtr fo@(ForeignPtr _ r) f = IO $ \s -> + case f (unsafeForeignPtrToPtr fo) of + IO action# -> keepAlive# r s action# -- | This is similar to 'withForeignPtr' but comes with an important caveat: -- the user must guarantee that the continuation does not diverge (e.g. loop or -- cgit v1.2.1