Skip to content

Commit

Permalink
Fix potential memory leak when reading / writing from a pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
ergl committed Apr 8, 2021
1 parent 7d38ffa commit 9e4ab1a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .release-notes/3741.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Fix possible memory leak

A possible memory leak in the process package was fixed.
8 changes: 4 additions & 4 deletions packages/process/_pipe.pony
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class _Pipe
=>
ifdef posix then
let len =
@read[ISize](near_fd, read_buf.cpointer().usize() + offset,
@read[ISize](near_fd, read_buf.cpointer(offset),
read_buf.size() - offset)
if len == -1 then // OS signals write error
(consume read_buf, len, @pony_os_errno())
Expand Down Expand Up @@ -175,7 +175,7 @@ class _Pipe
end
// Read up to the bytes available
var bytes_read: U32 = 0
let ok = @ReadFile[Bool](hnd, read_buf.cpointer().usize() + offset,
let ok = @ReadFile[Bool](hnd, read_buf.cpointer(offset),
bytes_to_read, addressof bytes_read, USize(0))
let winerr = @GetLastError[I32]()
if not ok then
Expand All @@ -196,7 +196,7 @@ class _Pipe
fun ref write(data: ByteSeq box, offset: USize): (ISize, I32) =>
ifdef posix then
let len = @write[ISize](
near_fd, data.cpointer().usize() + offset, data.size() - offset)
near_fd, data.cpointer(offset), data.size() - offset)
if len == -1 then // OS signals write error
(len, @pony_os_errno())
else
Expand All @@ -206,7 +206,7 @@ class _Pipe
let hnd: USize = @_get_osfhandle[USize](near_fd)
let bytes_to_write: U32 = (data.size() - offset).u32()
var bytes_written: U32 = 0
let ok = @WriteFile[Bool](hnd, data.cpointer().usize() + offset,
let ok = @WriteFile[Bool](hnd, data.cpointer(offset),
bytes_to_write, addressof bytes_written, USize(0))
let winerr = @GetLastError[I32]()
if not ok then
Expand Down

0 comments on commit 9e4ab1a

Please sign in to comment.