Storable (Maybe a) leaks memory?

In the C2HS.hs which is generated by 'c2hs -l', I found this code: instance Storable a => Storable (Maybe a) where sizeOf _ = sizeOf (undefined :: Ptr ()) alignment _ = alignment (undefined :: Ptr ()) peek p = do ptr <- peek (castPtr p) if ptr == nullPtr then return Nothing else liftM Just $ peek ptr poke p v = do ptr <- case v of Nothing -> return nullPtr Just v' -> new v' poke (castPtr p) ptr In the poke implementation, 'Foreign.Marshal.Utils.new' is used. 'new' uses malloc, and would thus most likely lead to memory leaks, since the user of this instance probably doesn't know that he needs to free the block pointed to by the written value. Or did I miss something clever here? The best alternative I can see is to restrict it to Storable a => Storable (Maybe (Ptr a)), and skip the call to 'new', but that requires extensions. /Björn

On Mon, 2007-06-11 at 00:53 +0200, Bjorn Bringert wrote:
In the C2HS.hs which is generated by 'c2hs -l', I found this code:
I'm inclined to remove C2HS.hs completely. Currently c2hs does generate code that uses things in C2HS.hs however it only uses a small subset and those are really simple things that could just be included inline. Duncan
participants (2)
-
Bjorn Bringert
-
Duncan Coutts