on master help sign in
Merge pull request #4413 from jacereda/messaging-leak

getMsg leak

commite4d006a53d15bc1385a10d0fb4f5f1de55bd81b1 authorNiklas Larsson <metaniklas@gmail.com> dateMon 9 Apr 2018, 00:57 (9 years ago) parent9d62d286a14b2a
1 file changed+9−10
libs/base/System/Concurrency/Raw.idr+9−10
libs/base/System/Concurrency/Raw.idr+9−10
@@ -8,7 +8,7 @@ import System
88
99||| Send a message of any type to the thread with the given thread id
1010||| Returns channel ID if the message was sent successfully, 0 otherwise
11−|||
11+|||
1212||| @channel an ID of a specific channel to send the message on. If 0,
1313||| the receiver will create a new channel ID
1414sendToThread : (thread_id : Ptr) -> (channel : Int) -> a -> IO Int
@@ -29,7 +29,7 @@ checkMsgs = do me <- getMyVM
2929checkMsgsTimeout : Int -> IO Bool
3030checkMsgsTimeout timeout
3131 = do me <- getMyVM
32− msgs <- foreign FFI_C "idris_checkMessagesTimeout"
32+ msgs <- foreign FFI_C "idris_checkMessagesTimeout"
3333 (Ptr -> Int -> IO Ptr) me timeout
3434 null <- nullPtr msgs
3535 pure (not null)
@@ -43,7 +43,7 @@ channel_id : Ptr -> IO Int
4343channel_id msg = foreign FFI_C "idris_getChannel" (Ptr -> IO Int) msg
4444
4545||| Check for messages initiating a conversation in the process inbox.
46−||| Returns either 'Nothing', if none, or 'Just (pid, channel)' as pid
46+||| Returns either 'Nothing', if none, or 'Just (pid, channel)' as pid
4747||| of sender and new channel id.
4848listenMsgs : IO (Maybe (Ptr, Int))
4949listenMsgs = do me <- getMyVM
@@ -58,7 +58,7 @@ listenMsgs = do me <- getMyVM
5858||| Check for messages from a specific sender/channel in the process inbox
5959||| If channel is '0', accept on any channel.
6060checkMsgsFrom : Ptr -> (channel : Int) -> IO Bool
61−checkMsgsFrom sender channel
61+checkMsgsFrom sender channel
6262 = do me <- getMyVM
6363 msgs <- foreign FFI_C "idris_checkMessagesFrom" (Ptr -> Int -> Ptr -> IO Ptr)
6464 me channel sender
@@ -73,6 +73,7 @@ getMsg : IO a
7373getMsg {a} = do me <- getMyVM
7474 m <- foreign FFI_C "idris_recvMessage" (Ptr -> IO Ptr) me
7575 MkRaw x <- foreign FFI_C "idris_getMsg" (Ptr -> IO (Raw a)) m
76+ foreign FFI_C "idris_freeMsg" (Ptr -> IO ()) m
7677 pure x
7778
7879||| Check inbox for messages. If there are none, blocks until a message
@@ -80,9 +81,9 @@ getMsg {a} = do me <- getMyVM
8081||| Note that this is not at all type safe! It is intended to be used in
8182||| a type safe wrapper.
8283getMsgWithSender : IO (Ptr, Int, a)
83−getMsgWithSender {a}
84+getMsgWithSender {a}
8485 = do me <- getMyVM
85− m <- foreign FFI_C "idris_recvMessage"
86+ m <- foreign FFI_C "idris_recvMessage"
8687 (Ptr -> IO Ptr) me
8788 MkRaw x <- foreign FFI_C "idris_getMsg" (Ptr -> IO (Raw a)) m
8889 vm <- sender m
@@ -94,12 +95,12 @@ getMsgWithSender {a}
9495||| blocks until a message arrives. Returns `Nothing` if the sender isn't
9596||| alive
9697getMsgFrom : Ptr -> (channel : Int) -> IO (Maybe a)
97−getMsgFrom {a} sender channel
98+getMsgFrom {a} sender channel
9899 = do me <- getMyVM
99100 m <- foreign FFI_C "idris_recvMessageFrom"
100101 (Ptr -> Int -> Ptr -> IO Ptr) me channel sender
101102 null <- nullPtr m
102− if null
103+ if null
103104 then pure Nothing
104105 else do
105106 MkRaw x <- foreign FFI_C "idris_getMsg" (Ptr -> IO (Raw a)) m
@@ -110,5 +111,3 @@ stopThread : IO a
110111stopThread = do vm <- getMyVM
111112 MkRaw res <- foreign FFI_C "idris_stopThread" (Ptr -> IO (Raw a)) vm
112113 pure res
113−
114−