Skip to content

Memory Leak on Windows when using Fiddle::Pointer #165

@szymonj99

Description

@szymonj99

Looking at the Fiddle docs here: https://docs.ruby-lang.org/en/master/Fiddle/Pointer.html
We can see an example incorrect usage resulting in a memory leak:

# No free function and no call to free - the native memory will leak if the pointer is garbage collected
pointer = Fiddle::Pointer.malloc(size)

The above approach is what's used in this library, for example:

csbi = Fiddle::Pointer.malloc(24)

Correct usage, not resulting in a memory leak, taken from the Fiddle docs:

# Automatically freeing the pointer when the block is exited - recommended
Fiddle::Pointer.malloc(24, Fiddle::RUBY_FREE) do |csbi|
  @GetConsoleScreenBufferInfo.Call(@hConsoleHandle,csbi)
  x,y = csbi[4,4].unpack('SS')
end
x = dpos
@SetConsoleCursorPosition.Call(@hConsoleHandle,y*65536+x)
@_rl_last_c_pos = dpos

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions