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

double free or corruption #1596

Closed
513198868 opened this issue Jun 20, 2023 · 3 comments
Closed

double free or corruption #1596

513198868 opened this issue Jun 20, 2023 · 3 comments

Comments

@513198868
Copy link

double free or corruption (out)

Thread 3 "agent_server" received signal SIGABRT, Aborted.
[Switching to Thread 0x7ff734e1c0 (LWP 2797432)]
0x0000007ff7b83eac in raise () from /lib/aarch64-linux-gnu/libc.so.6
(gdb) bt
#0 0x0000007ff7b83eac in raise () from /lib/aarch64-linux-gnu/libc.so.6
#1 0x0000007ff7b70aa0 in abort () from /lib/aarch64-linux-gnu/libc.so.6
#2 0x0000007ff7bbde80 in ?? () from /lib/aarch64-linux-gnu/libc.so.6
#3 0x0000007ff7bc53dc in ?? () from /lib/aarch64-linux-gnu/libc.so.6
#4 0x0000007ff7bc6820 in ?? () from /lib/aarch64-linux-gnu/libc.so.6
#5 0x000000000040dd28 in std::default_deletehttplib::Response::operator() (this=, __ptr=0x7fec001bb0) at /root/gccLib/aarch64-linux-gnu/include/c++/7.5.0/bits/unique_ptr.h:78
#6 std::unique_ptr<httplib::Response, std::default_deletehttplib::Response >::~unique_ptr (this=0x7ff734c5c0, __in_chrg=) at /root/gccLib/aarch64-linux-gnu/include/c++/7.5.0/bits/unique_ptr.h:263
#7 httplib::Result::~Result (this=0x7ff734c5c0, in_chrg=) at httplib.h:795
#8 VirtualMeal::registerHostMachine (hostMachineInfo=...,
ip="\200\000\000\264\363\v@\371\375{¨\300\003
\326\001\337\377\227`\000\000\264\000\000?\326\367\377\377\027\000\001\200?\341\377\227\203\t\000?\t\000Ё\t\000\260c<B\371B\364F\371c@\000\221!TG\371\003\000\000\371
\343\377\227\037 \003\325\037 \003\325\375{\277\251\375\003\000\221j\335\377\227", port=port@entry=58110) at VirtualMeal.cpp:1256
#9 0x000000000041224c in VirtualMeal::<lambda(const httplib::Request&, httplib::Response&, const httplib::ContentReader&)>::operator()(httplib::Response &, const httplib::ContentReader &, const httplib::Request &) (res=...,
content_reader=..., req=..., __closure=) at VirtualMeal.cpp:195
#10 0x000000000043b624 in std::function<void (httplib::Request const&, httplib::Response&, httplib::ContentReader const&)>::operator()(httplib::Request const&, httplib::Response&, httplib::ContentReader const&) const (__args#2=...,
__args#1=..., __args#0=..., this=0x496300) at /root/gccLib/aarch64-linux-gnu/include/c++/7.5.0/bits/std_function.h:706
#11 httplib::Server::dispatch_request_for_content_reader(httplib::Request&, httplib::Response&, httplib::ContentReader, std::vector<std::pair<std::__cxx11::basic_regex<char, std::__cxx11::regex_traits >, std::function<void (httplib::Request const&, httplib::Response&, httplib::ContentReader const&)> >, std::allocator<std::pair<std::__cxx11::basic_regex<char, std::__cxx11::regex_traits >, std::function<void (httplib::Request const&, httplib::Response&, httplib::ContentReader const&)> > > > const&) (req=..., res=..., content_reader=..., handlers=std::vector of length 11, capacity 16 = {...}, this=0x7ffffff2f0) at httplib.h:5006
#12 0x000000000044a330 in httplib::Server::routing (this=this@entry=0x7ffffff2f0, req=..., res=..., strm=...) at httplib.h:4825
#13 0x000000000044c328 in httplib::Server::process_request(httplib::Stream&, bool, bool&, std::function<void (httplib::Request&)> const&) (this=0x7ffffff2f0, this@entry=0x0, strm=..., close_connection=close_connection@entry=false,
connection_closed=connection_closed@entry=@0x7ff734d8df: false, setup_request=...) at httplib.h:5099
#14 0x000000000044c7b4 in httplib::Server::process_and_close_socket(int)::{lambda(httplib::Stream&, bool, bool&)#1}::operator()(httplib::Stream&, bool, bool&) const (connection_closed=@0x7ff734d8df: false, close_connection=false,
strm=..., __closure=) at httplib.h:5131
#15 httplib::detail::process_server_socket<httplib::Server::process_and_close_socket(int)::{lambda(httplib::Stream&, bool, bool&)#1}>(int, unsigned long, long, long, long, long, long, httplib::Server::process_and_close_socket(int)::{lambda(httplib::Stream&, bool, bool&)#1})::{lambda(bool, bool&)#1}::operator()(bool, bool&) const (connection_closed=@0x7ff734d8df: false, close_connection=false, __closure=) at httplib.h:2012
#16 httplib::detail::process_server_socket_core<httplib::detail::process_server_socket<httplib::Server::process_and_close_socket(int)::{lambda(httplib::Stream&, bool, bool&)#1}>(int, unsigned long, long, long, long, long, long, httplib::Server::process_and_close_socket(int)::{lambda(httplib::Stream&, bool, bool&)#1})::{lambda(bool, bool&)#1}>(int, unsigned long, long, httplib::detail::process_server_socket<httplib::Server::process_and_close_socket(int)::{lambda(httplib::Stream&, bool, bool&)#1}>(int, unsigned long, long, long, long, long, long, httplib::Server::process_and_close_socket(int)::{lambda(httplib::Stream&, bool, bool&)#1})::{lambda(bool, bool&)#1}) (callback=...,
keep_alive_timeout_sec=, keep_alive_max_count=, sock=) at httplib.h:1994
#17 httplib::detail::process_server_socket<httplib::Server::process_and_close_socket(int)::{lambda(httplib::Stream&, bool, bool&)#1}>(int, unsigned long, long, long, long, long, long, httplib::Server::process_and_close_socket(int)::{lambda(httplib::Stream&, bool, bool&)#1}) (callback=..., write_timeout_usec=, write_timeout_sec=, read_timeout_usec=, read_timeout_sec=, keep_alive_timeout_sec=,
keep_alive_max_count=, sock=) at httplib.h:2013
#18 httplib::Server::process_and_close_socket (this=0x0, sock=0) at httplib.h:5131
#19 0x0000000000428518 in std::function<void ()>::operator()() const (this=0x7ff734d970) at /root/gccLib/aarch64-linux-gnu/include/c++/7.5.0/bits/std_function.h:706
#20 httplib::ThreadPool::worker::operator() (this=0x497818) at httplib.h:558
#21 std::__invoke_impl<void, httplib::ThreadPool::worker> (__f=...) at /root/gccLib/aarch64-linux-gnu/include/c++/7.5.0/bits/invoke.h:60
#22 std::__invokehttplib::ThreadPool::worker (__fn=...) at /root/gccLib/aarch64-linux-gnu/include/c++/7.5.0/bits/invoke.h:95
#23 std::thread::_Invoker<std::tuplehttplib::ThreadPool::worker >::_M_invoke<0ul> (this=0x497818) at /root/gccLib/aarch64-linux-gnu/include/c++/7.5.0/thread:234
#24 std::thread::_Invoker<std::tuplehttplib::ThreadPool::worker >::operator() (this=0x497818) at /root/gccLib/aarch64-linux-gnu/include/c++/7.5.0/thread:243
#25 std::thread::_State_impl<std::thread::_Invoker<std::tuplehttplib::ThreadPool::worker > >::_M_run (this=0x497810) at /root/gccLib/aarch64-linux-gnu/include/c++/7.5.0/thread:186
#26 0x0000007ff7e5dcac in ?? () from /lib/aarch64-linux-gnu/libstdc++.so.6
#27 0x0000007ff7f73648 in start_thread () from /lib/aarch64-linux-gnu/libpthread.so.0
#28 0x0000007ff7c22c1c in ?? () from /lib/aarch64-linux-gnu/libc.so.6
(gdb) quit
A debugging session is active.

@yhirose
Copy link
Owner

yhirose commented Jun 20, 2023

@513198868 thanks for the report, but it's too little information for me to take a look at. Could you provide the smallest possible code which reproduce the problem? Otherwise, I am not able to confirm if it's a bug in cpp-httplib or not. Thanks!

@513198868
Copy link
Author

server.Post("/set", [&](const httplib::Request &req, httplib::Response &res, const httplib::ContentReader &content_reader)
{
std::string body;
content_reader([&](const char *data, size_t data_length)
{
body.append(data, data_length);
return true;
});
cJSON *root = cJSON_Parse(body.c_str());
if (root)
{
string ip = cJSON_GetObjectItem(root, "ip")->valuestring;
int port = cJSON_GetObjectItem(root, "port")->valueint;
if (port == 0)
{
port = atoi(cJSON_GetObjectItem(root, "port")->valuestring);
}
cJSON_Delete(root);
if (!ip.empty() && port != 0)
{
HostMachineInfo hostMachineInfo;
getHostMachineInfo(hostMachineInfo);
registerHostMachine(hostMachineInfo, ip, port);
}
writeHostConfig(ip, port);
res.set_content("{"status":"0","data":"","msg":"success"}", "application/json");
}
else
{
res.set_content("{"status":"1","msg":"fail"}", "application/json");
} });

void VirtualMeal::registerHostMachine(const HostMachineInfo &hostMachineInfo, const string &ip, int port)
{
httplib::Client client(ip, port);
cJSON *hostMachineJson = cJSON_CreateObject();
cJSON_AddStringToObject(hostMachineJson, "sn", hostMachineInfo.sn.c_str());
agentServerLog(FUNCTION, LINE, "hostMachineJson", cJSON_Print(hostMachineJson));
auto res = client.Post("/registerHostInfo", cJSON_Print(hostMachineJson), "application/json");
if (res)
{
agentServerLog(FUNCTION, LINE, "res->status", res->status);
agentServerLog(FUNCTION, LINE, "res->body", res->body);
}
}

Running in the Linux environment, some environments can run normally, and some do not

@yhirose
Copy link
Owner

yhirose commented Jun 21, 2023

It looks like cJSON *hostMachineJson = cJSON_CreateObject(); isn't freed.

@yhirose yhirose closed this as completed Jun 26, 2023
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