caoniaocoder414 opened a new issue, #2412:
URL: https://github.com/apache/brpc/issues/2412
**Describe the bug (描述bug)**
#include <iostream>
#include <gflags/gflags.h>
#include <butil/logging.h>
#include <butil/time.h>
#include <brpc/channel.h>
#include "netcvm.pb.h"
using namespace std;
DEFINE_string(attachment, "", "Carry this along with requests");
DEFINE_string(protocol, "baidu_std", "Protocol type. Defined in
src/brpc/options.proto");
DEFINE_string(connection_type, "", "Connection type. Available values:
single, pooled, short");
DEFINE_string(server, "127.0.0.1:2365", "IP Address of server");
DEFINE_string(load_balancer, "", "The algorithm for load balancing");
DEFINE_int32(timeout_ms, 100, "RPC timeout in milliseconds");
DEFINE_int32(max_retry, 3, "Max retries(not including the first RPC)");
DEFINE_int32(interval_ms, 1000, "Milliseconds between consecutive requests");
void OLResponse(brpc::Controller* cntl, netcvm::OnlineResponse* response)
{
std::unique_ptr<brpc::Controller> cntl_guard(cntl);
std::unique_ptr<netcvm::OnlineResponse> response_guard(response);
printf("Agent online!\n");
if (cntl->Failed()) {
printf("cntl failed\n");
return;
}
if(response->code() != 0 ) {
printf("Agent register failed!\n");
}
printf("code:%d\n",response->code());
}
int main()
{
// A Channel represents a communication line to a Server. Notice that
// Channel is thread-safe and can be shared by all threads in your
program.
brpc::Channel channel;
// Initialize the channel, NULL means using default options.
brpc::ChannelOptions options;
options.protocol = FLAGS_protocol;
options.connection_type = FLAGS_connection_type;
options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/;
options.max_retry = FLAGS_max_retry;
if (channel.Init("10.80.81.107:8998", &options) != 0) {
LOG(ERROR) << "Fail to initialize channel";
printf("init failed!\n");
return -1;
}
printf("init success\n");
netcvm::cvm_data_service_Stub stub(&channel);
netcvm::OnlineRequest request;
request.set_agentserial("aaa");
request.set_paramstr("aaa");
netcvm::OnlineResponse response;
brpc::Controller cntl ;
netcvm::OnlineResponse *newresponse = new (std::nothrow)
netcvm::OnlineResponse();
brpc::Controller *newcntl = new (std::nothrow) brpc::Controller();
google::protobuf::Closure *done = brpc::NewCallback(&OLResponse,
newcntl, newresponse);
if(done == NULL){
printf("online google::protobuf::Closure malloc failed!\n");
return -1;
}
stub.Online(&cntl, &request, &response, done);
sleep(2);
return 0;
}
使用 valgrind 检查发现 65,792 bytes in 4 blocks are still reachable in loss record
1,424 of 1,449
==00:00:24:07.934 26429== 65,792 bytes in 4 blocks are still reachable in
loss record 1,424 of 1,449
==00:00:24:07.934 26429== at 0x4C2A7E6: operator new(unsigned long,
std::nothrow_t const&) (vg_replace_malloc.c:387)
==00:00:24:07.934 26429== by 0x6145500: add_block
(resource_pool_inl.h:387)
==00:00:24:07.934 26429== by 0x6145500: get (resource_pool_inl.h:210)
==00:00:24:07.934 26429== by 0x6145500: get_resource
(resource_pool_inl.h:283)
==00:00:24:07.934 26429== by 0x6145500:
get_resource<bthread::TimerThread::Task> (resource_pool.h:97)
==00:00:24:07.934 26429== by 0x6145500:
bthread::TimerThread::Bucket::schedule(void (*)(void*), void*, timespec const&)
(timer_thread.cpp:187)
==00:00:24:07.934 26429== by 0x6145876:
bthread::TimerThread::schedule(void (*)(void*), void*, timespec const&)
(timer_thread.cpp:226)
==00:00:24:07.934 26429== by 0x6148DC1: bthread_timer_add
(bthread.cpp:335)
==00:00:24:07.934 26429== by 0x621F58B:
brpc::Channel::CallMethod(google::protobuf::MethodDescriptor const*,
google::protobuf::RpcController*, google::protobuf::Message const*,
google::protobuf::Message*, google::protobuf::Closure*) (channel.cpp:520)
==00:00:24:07.934 26429== by 0x52E2C7:
Report::Trigger(netcvm::ReportDevPolicyRequest&) (ev_report.cpp:24)
==00:00:24:07.934 26429== by 0x493BCA: DevHBTask::execute(int)
(dev_hb_task.cpp:50)
==00:00:24:07.934 26429== by 0x49012F: ThreadPool::runtime(void*)
(actuator.cpp:85)
==00:00:24:07.934 26429== by 0x825840E: execute_native_thread_routine (in
/opt/csa/csa_lib/lib/libmydtls1.0.so)
==00:00:24:07.934 26429== by 0x9085EA4: start_thread (in
/usr/lib64/libpthread-2.17.so)
==00:00:24:07.934 26429== by 0x9BB8B0C: clone (in /usr/lib64/libc-2.17.so)
**To Reproduce (复现方法)**
使用上述代码
**Expected behavior (期望行为)**
是某个函数释放不对吗?
**Versions (各种版本)**
OS:
Compiler:
brpc:
protobuf:
**Additional context/screenshots (更多上下文/截图)**
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]