Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
szymonj99 opened this issue Oct 30, 2024 · 0 comments
Open

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

szymonj99 opened this issue Oct 30, 2024 · 0 comments

Comments

@szymonj99
Copy link

szymonj99 commented Oct 30, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant