Skip to content

Avoid memory leak #2

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

Open
wants to merge 1 commit into
base: github
Choose a base branch
from
Open

Avoid memory leak #2

wants to merge 1 commit into from

Conversation

jhawthorn
Copy link

This fixes a very minor memory leak, which should only happen one time during boot.

ASAN_OPTIONS="detect_leaks=1" RUBY_FREE_AT_EXIT=1 bin/safe-ruby -e 'require "memcached"; 1000.times { lib = Memcached.const_get(:Lib); lib.memcached_create(lib.memcached_create(nil)) }'
-e: warning: Free at exit is experimental and may be unstable

=================================================================
==270021==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 704000 byte(s) in 1000 object(s) allocated from:
    #0 0x561b2c54c789 in calloc (/workspaces/github/vendor/ruby/a1148d4aada8b3bb2e1c370766baad11c28edf23/bin/ruby+0x20e789) (BuildId: 4150ff2af984fe843bd61bcb9247693bf25c58c9)
    #1 0x77c6d5d6e6aa in memcached_create /workspaces/github/vendor/gems/3.4.0/ruby/3.4.0+0/bundler/gems/memcached-9429dfc17895/vendor/libmemcached-0.32/libmemcached/memcached.c:12:26
    #2 0x77c6d5d54fe9 in _wrap_memcached_create /workspaces/github/vendor/gems/3.4.0/ruby/3.4.0+0/bundler/gems/memcached-9429dfc17895/ext/rlibmemcached/rlibmemcached_wrap.c:6955:28
    #3 0x561b2c8d809a in vm_call_cfunc_with_frame_ /workspaces/github/vendor/ruby/src/./vm_insnhelper.c:3795:11

A more proper fix might be to make Lib.memcached_create(existing_struct) not leak memory, but this is easier and this is an old abandoned branch.

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.

1 participant