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 running test #1839

Closed
weinberggithub opened this issue May 17, 2024 · 7 comments
Closed

memory leak running test #1839

weinberggithub opened this issue May 17, 2024 · 7 comments

Comments

@weinberggithub
Copy link

weinberggithub commented May 17, 2024

I run the unit test with asan, ASAN_OPTIONS=detect_leaks=1 ./httplib-test
cpp-httplib: commit of 3b6597b on master branch
os: macos ventura 13.5
compiler: clang-1500.1.0.2.5
below is one of the stack

Indirect leak of 128 byte(s) in 1 object(s) allocated from:
    #0 0x103a7bc8c in calloc+0x94 (libclang_rt.asan_osx_dynamic.dylib:arm64+0x53c8c)
    #1 0x19a936740 in _objc_rootAllocWithZone+0x24 (libobjc.A.dylib:arm64+0xe740)
    #2 0x490680019a95cadc  (<unknown module>)
    #3 0x67388001a1b7f7f8  (<unknown module>)
    #4 0x595c0001a196f004  (<unknown module>)
    #5 0xfc118001a196ebe4  (<unknown module>)
    #6 0xd31a0001a196e4e4  (<unknown module>)
    #7 0xde100001a196d300  (<unknown module>)
    #8 0x27350001a17dc220  (<unknown module>)
    #9 0xa26b80019ad17238  (<unknown module>)
    #10 0xa6980019ad03ca0  (<unknown module>)
    #11 0x671a80019ad03734  (<unknown module>)
    #12 0x173c000103a537d0  (<unknown module>)
    #13 0x10264dc34 in int httplib::detail::create_socket<httplib::detail::create_client_socket(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, int, int, bool, std::__1::function<void (int)>, long, long, long, long, long, long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, httplib::Error&)::'lambda'(int, addrinfo&)>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, int, int, int, bool, std::__1::function<void (int)>, httplib::detail::create_client_socket(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, int, int, bool, std::__1::function<void (int)>, long, long, long, long, long, long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, httplib::Error&)::'lambda'(int, addrinfo&)) httplib.h:3243
    #14 0x10264d620 in httplib::detail::create_client_socket(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, int, int, bool, std::__1::function<void (int)>, long, long, long, long, long, long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, httplib::Error&) httplib.h:3414
    #15 0x10264cbdc in httplib::ClientImpl::create_client_socket(httplib::Error&) const httplib.h:6990
    #16 0x1027273f4 in httplib::SSLClient::create_and_connect_socket(httplib::ClientImpl::Socket&, httplib::Error&) httplib.h:8885
    #17 0x1026dcf70 in httplib::ClientImpl::send_(httplib::Request&, httplib::Response&, httplib::Error&) httplib.h:7107
    #18 0x102646674 in httplib::ClientImpl::send_(httplib::Request&&) httplib.h:7180
    #19 0x102646230 in httplib::ClientImpl::Get(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::multimap<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, httplib::detail::ci, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>>> const&, std::__1::function<bool (unsigned long long, unsigned long long)>) httplib.h:7720
    #20 0x1024242b0 in RangeTest_FromHTTPBin_Online_Test::TestBody() test.cc:660
    #21 0x1028d15f0 in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) gtest.cc:2671
    #22 0x1028d12f4 in testing::Test::Run() gtest.cc:2710
    #23 0x1028d3ec0 in testing::TestInfo::Run() gtest.cc:2856
    #24 0x1028d66a8 in testing::TestSuite::Run() gtest.cc:3034
    #25 0x10290d1f8 in testing::internal::UnitTestImpl::RunAllTests() gtest.cc:5964
    #26 0x10290c274 in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) gtest.cc:2671
    #27 0x10290c014 in testing::UnitTest::Run() gtest.cc:5543
    #28 0x102883930 in main gtest_main.cc:64
    #29 0x19a973f24  (<unknown module>)
@yhirose
Copy link
Owner

yhirose commented May 17, 2024

@weinberggithub do you mean that this problem starts happening since the commit 3b6597b?

@weinberggithub
Copy link
Author

@weinberggithub do you mean that this problem starts happening since the commit 3b6597b?

no,I mean my test based on this commit

@yhirose
Copy link
Owner

yhirose commented May 26, 2024

@weinberggithub could you try with f10720e?

@weinberggithub
Copy link
Author

@weinberggithub could you try with f10720e?

httplib.txt
this is the result.

@yhirose
Copy link
Owner

yhirose commented May 27, 2024

I'll try to reproduce the problem on my machine. How did you make your httplib-test which supports ASAN_OPTIONS=detect_leaks=1 with cmake?

@weinberggithub
Copy link
Author

I'll try to reproduce the problem on my machine. How did you make your httplib-test which supports ASAN_OPTIONS=detect_leaks=1 with cmake?

set(CMAKE_CXX_COMPILER "/opt/homebrew/opt/llvm@17/bin/clang++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -g -O1")

on macos(M2, apple chips), simply add two line to CMakeLists.txt and enable HTTPLIB-TEST.

@yhirose
Copy link
Owner

yhirose commented Aug 30, 2024

@weinberggithub sorry for the late reply. I just tried your suggestion, but it reports a lot of errors which are not apparently caused by cpp-htpplib. For instance, the following command doesn't run any unit test, but it still reports many errors...

ASAN_OPTIONS=detect_leaks=1 ./httplib-test --gtest_filter="AAA"

It seems like gtest anyway causes lots of memory leaks, and I am not sure that the leak report for cpp-httplib is really true.

In the past, I did test with apache bench and wrk by sending many requests to a server for long time, and made sure that there was no symptom indicating a possibility of memory leak. I did it again now, and I don't see any problem. So I'll close it for now, since I don't see any clear evidence.

Could you identify exact lines in httplib.h which are absolutely causing memory leaks with a simple example instead of the unit test, and when you find a problem with the simple problem, please create a new issue. Thanks for your understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants