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

[BUG] memory leak detected when calling AsyncRedisCluster::redis(sw::redis::StringView const&, bool) #543

Closed
mroland91 opened this issue Jan 23, 2024 · 3 comments

Comments

@mroland91
Copy link

Describe the bug
I have a WIP project where I am integrating redis++ (thanks for making it BTW!).
After upgrading to the latest 1.3.11 Valgrind reported a memory error. I've also used 1.3.8 and 1.3.10 for a longer period and this problem was not present on those releases.

To Reproduce

auto event_loop = std::shared_ptr<sw::redis::EventLoop>();
sw::redis::ConnectionOptions opts;
opts.keep_alive = true;
opts.host = "localhost";
opts.port = 6379;
opts.resp = 3;
auto redis_cluster = std::make_shared<sw::redis::AsyncRedisCluster>(opts, sw::redis::ConnectionPoolOptions{}, sw::redis::Role::MASTER, event_loop);
sw::redis::Future<std::string> ping_future = redis_cluster->redis("key1", false).ping();
...

Environment:

  • OS: Rocky Linux 8
  • Compiler: gcc 8.5.0
  • hiredis version: 1.2.0
  • redis-plus-plus version:1.3.11

Additional context

==6011== Memcheck, a memory error detector
==6011== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==6011== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==6011== Command: /redis-client-test
==6011== Parent PID: 6010
==6011== 
==6011== 
==6011== HEAP SUMMARY:
==6011==     in use at exit: 21,523 bytes in 30 blocks
==6011==   total heap usage: 3,648 allocs, 3,618 frees, 546,766 bytes allocated
==6011== 
==6011== 2,510 (552 direct, 1,958 indirect) bytes in 1 blocks are definitely lost in loss record 21 of 22
==6011==    at 0x4C388C3: operator new(unsigned long) (vg_replace_malloc.c:422)
==6011==    by 0x6B06E31: allocate (new_allocator.h:111)
==6011==    by 0x6B06E31: allocate (alloc_traits.h:436)
==6011==    by 0x6B06E31: __allocate_guarded<std::allocator<std::_Sp_counted_ptr_inplace<sw::redis::AsyncConnection, std::allocator<sw::redis::AsyncConnection>, (__gnu_cxx::_Lock_policy)2> > > (allocated_ptr.h:97)
==6011==    by 0x6B06E31: __shared_count<sw::redis::AsyncConnection, std::allocator<sw::redis::AsyncConnection>, sw::redis::ConnectionOptions&, sw::redis::EventLoop*> (shared_ptr_base.h:675)
==6011==    by 0x6B06E31: __shared_ptr<std::allocator<sw::redis::AsyncConnection>, sw::redis::ConnectionOptions&, sw::redis::EventLoop*> (shared_ptr_base.h:1342)
==6011==    by 0x6B06E31: shared_ptr<std::allocator<sw::redis::AsyncConnection>, sw::redis::ConnectionOptions&, sw::redis::EventLoop*> (shared_ptr.h:359)
==6011==    by 0x6B06E31: allocate_shared<sw::redis::AsyncConnection, std::allocator<sw::redis::AsyncConnection>, sw::redis::ConnectionOptions&, sw::redis::EventLoop*> (shared_ptr.h:708)
==6011==    by 0x6B06E31: make_shared<sw::redis::AsyncConnection, sw::redis::ConnectionOptions&, sw::redis::EventLoop*> (shared_ptr.h:724)
==6011==    by 0x6B06E31: sw::redis::AsyncConnectionPool::_create() (async_connection_pool.cpp:273)
==6011==    by 0x6B078B0: sw::redis::AsyncConnectionPool::fetch() (async_connection_pool.cpp:120)
==6011==    by 0x6B0071D: sw::redis::GuardedAsyncConnection::GuardedAsyncConnection(std::shared_ptr<sw::redis::AsyncConnectionPool> const&) (async_connection.cpp:586)
==6011==    by 0x6B0FC28: construct<sw::redis::GuardedAsyncConnection, std::shared_ptr<sw::redis::AsyncConnectionPool>&> (new_allocator.h:136)
==6011==    by 0x6B0FC28: construct<sw::redis::GuardedAsyncConnection, std::shared_ptr<sw::redis::AsyncConnectionPool>&> (alloc_traits.h:475)
==6011==    by 0x6B0FC28: _Sp_counted_ptr_inplace<std::shared_ptr<sw::redis::AsyncConnectionPool>&> (shared_ptr_base.h:545)
==6011==    by 0x6B0FC28: __shared_count<sw::redis::GuardedAsyncConnection, std::allocator<sw::redis::GuardedAsyncConnection>, std::shared_ptr<sw::redis::AsyncConnectionPool>&> (shared_ptr_base.h:677)
==6011==    by 0x6B0FC28: __shared_ptr<std::allocator<sw::redis::GuardedAsyncConnection>, std::shared_ptr<sw::redis::AsyncConnectionPool>&> (shared_ptr_base.h:1342)
==6011==    by 0x6B0FC28: shared_ptr<std::allocator<sw::redis::GuardedAsyncConnection>, std::shared_ptr<sw::redis::AsyncConnectionPool>&> (shared_ptr.h:359)
==6011==    by 0x6B0FC28: allocate_shared<sw::redis::GuardedAsyncConnection, std::allocator<sw::redis::GuardedAsyncConnection>, std::shared_ptr<sw::redis::AsyncConnectionPool>&> (shared_ptr.h:708)
==6011==    by 0x6B0FC28: make_shared<sw::redis::GuardedAsyncConnection, std::shared_ptr<sw::redis::AsyncConnectionPool>&> (shared_ptr.h:724)
==6011==    by 0x6B0FC28: sw::redis::AsyncRedisCluster::redis(sw::redis::StringView const&, bool) (async_redis_cluster.cpp:49)
==6011==    by 0x49A9B8:  test() (test.cpp:891)
==6011==    by 0x453EC4:  Redis_Test::TestBody() (tc1.cpp:188)
==6011==    by 0x555AC2E: void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (in /usr/lib64/libgtest.so.1.8.0)
==6011==    by 0x554FE31: testing::Test::Run() (in /usr/lib64/libgtest.so.1.8.0)
==6011==    by 0x554FF77: testing::TestInfo::Run() (in /usr/lib64/libgtest.so.1.8.0)
==6011==    by 0x5550054: testing::TestCase::Run() (in /usr/lib64/libgtest.so.1.8.0)
==6011==    by 0x5550524: testing::internal::UnitTestImpl::RunAllTests() (in /usr/lib64/libgtest.so.1.8.0)
==6011== 
==6011== LEAK SUMMARY:
==6011==    definitely lost: 552 bytes in 1 blocks
==6011==    indirectly lost: 1,958 bytes in 20 blocks
==6011==      possibly lost: 384 bytes in 1 blocks
==6011==    still reachable: 18,629 bytes in 8 blocks
==6011==         suppressed: 0 bytes in 0 blocks
==6011== Reachable blocks (those to which a pointer was found) are not shown.
==6011== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==6011== 
==6011== For lists of detected and suppressed errors, rerun with: -s
==6011== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
@sewenew
Copy link
Owner

sewenew commented Jan 24, 2024

Thanks for reporting the bug! I'll take a look into it.

Regards

sewenew added a commit that referenced this issue Jan 31, 2024
@sewenew
Copy link
Owner

sewenew commented Feb 1, 2024

The problem has been fixed. Please check the latest code on master branch. I'll publish a new release after some more tests.

Sorry for the late reply. Too busy these days...

Regards

@mroland91
Copy link
Author

Thanks, the issue is resolved on the latest master.

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

2 participants