谷歌协议缓冲区中的扩展导致中止

时间:2016-10-03 12:56:44

标签: c++ protocol-buffers abort

我的原始协议消息类问题,它运行正常。

message StrategyMessage {
  required bytes name = 1;
  optional int64 timestamp = 3;
  extensions 33 to 63;

}

extend StrategyMessage {
    /// many optional fields

    optional int64 best_bid=39;
}

每当我使用粘贴下面的扩展字段时,都会给我错误。

strategy_message_.SetExtension(utils::strategy_controller::best_bid,best_bid_);
LOG_DEBUG(logger_, " Sending message to U/I \n");
if (!strategy_controller_client_->send_message(strategy_message_)) {
            LOG_DEBUG(logger_, "ERROR: couldn't send message to U/I\n");
}

这会产生错误。

10/03/16 17:48:07.593132144 D  Sending message to U/I 

libprotobuf FATAL google/protobuf/message_lite.cc:270] CHECK failed: (end) == (reinterpret_cast<uint8*>(data) + byte_size): 

Program received signal SIGABRT, Aborted.
[Switching to Thread 0x7fffd8de8700 (LWP 63533)]
0x00007ffff4ef25d7 in raise () from /lib64/libc.so.6
(gdb) 

但是当我按照下面的说明更改后运行它时,它就可以了。

strategy_message_.set_timestamp(timestamp);
LOG_DEBUG(logger_, " Sending message to U/I \n");
if (!strategy_controller_client_->send_message(strategy_message_)) {
            LOG_DEBUG(logger_, "ERROR: couldn't send message to U/I\n");
}

send_message()的实现如下所示。

bool StrategyControllerClient::send_message(StrategyMessage& msg) {
  if (server_side_fd_ < 0) {
    return false;
  }
  msg.set_server_ip(local_interface_ip_);
  return send_message_impl(msg, server_side_fd_);
}

bool StrategyControllerClient::send_message_impl(const ::google::protobuf::Message& msg, int fd) {
  uint32_t size = msg.ByteSize();
  if (size > nMaxSizeOfMessageToServer) {
    ERROR_LOG << ::utils::current_time_ns() << " Msg to Server is too big: " << size << "\n";
    ERROR_LOG << msg.DebugString() << "\n";
    return false;
  }
  message_allocator_lock_.lock();
  MessageToServer* tm = message_allocator_->allocate();
  message_allocator_lock_.unlock();
  tm->msg.fd_identifier = fd;
  tm->msg.data_iov[0].iov_len = size;
  msg.SerializeToArray(tm->msg.data_iov[0].iov_base, size);
  if (!network_io_manager_->send_msg(&tm->msg)) {  // We won't get a callback so deallocate
    ERROR_LOG << ::utils::current_time_ns() << " Error in sending message to Server(2)\n";
    ERROR_LOG << msg.DebugString() << "\n";
    message_allocator_lock_.lock();
    message_allocator_->deallocate(tm);
    message_allocator_lock_.unlock();
    return false;
  }
  return true;
}

编辑:该程序没有泄漏。

==68909== LEAK SUMMARY:
==68909==    definitely lost: 0 bytes in 0 blocks
==68909==    indirectly lost: 0 bytes in 0 blocks
==68909==      possibly lost: 19,778 bytes in 404 blocks
==68909==    still reachable: 280,616 bytes in 964 blocks
==68909==         suppressed: 0 bytes in 0 blocks
==68909== Reachable blocks (those to which a pointer was found) are not shown.
==68909== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==68909== 
==68909== ERROR SUMMARY: 322 errors from 322 contexts (suppressed: 2 from 2)

EDIT2:该程序正在中止。

msg.SerializeToArray(tm->msg.data_iov[0].iov_base, size);

0 个答案:

没有答案