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

[0.x] Fix memory leaks of string buffers #320

Merged
merged 2 commits into from
Nov 20, 2024

Conversation

jhawthorn
Copy link

@jhawthorn jhawthorn commented Nov 19, 2024

In a few places we were passing malloc'd memory to rb_str_new (and variants) and returning the resulting VALUE without freeing the passed C string buffer.

One of these leaks was introduced by #171 (we can see that some calls to free were lost in the rewrite), but others seem to predate that.

After this change I'm able to run ASAN_OPTIONS="detect_leaks=1" RUBY_FREE_AT_EXIT=1 bundle exec rake with an ASAN-built Ruby without errors.

require "commonmarker"
10.times do
  100.times do
    CommonMarker.render_html("hello, world\n"*10000)
  end
  puts `ps -orss= -p #$$`
end

❯ bundle exec ruby test.rb
74736
112112
112112
128496
172016
203120
203120
203120
241392
266480

cc @anticomputer @phillmv

Copy link
Collaborator

@kivikakk kivikakk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :) Thank you!

@kivikakk kivikakk merged commit 5d9976b into gjtorikian:c-api-stable Nov 20, 2024
4 checks passed
@gjtorikian
Copy link
Owner

After two years of managing this fork I think it’s fair to ask: can y’all please move to the 1.x/Rust-backed version?

@gjtorikian
Copy link
Owner

@jhawthorn Please, don’t interpret my comment as hostility. I literally had a panic attack after the PR merged because I wasn’t sure if the C-backed gem was still auto deploying or not; it’s been a while since the last cut and I didn’t know if I would get a ping about the gem not being released.

I would like to remove the part of my brain that worries about this old gem being a part of your infrastructure. Let me know if there’s anything I can do to help update.

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

Successfully merging this pull request may close these issues.

3 participants