Stringfy rapidjson触发随机分段故障

时间:2015-11-30 07:42:24

标签: c++ string rapidjson

我的代码是将json文档转换为字符串:

class JMSG_C: public rapidjson::Document
{
  inline std::string JMSG_C::get_msg_str()
  {
    // Convert JSON document to string
    rapidjson::StringBuffer buffer;
    rapidjson::Writer< rapidjson::StringBuffer > writer(buffer);
    Accept(writer);
    std::string str = buffer.GetString();
    return str;
  }
}

函数get_msg_str()在分段错误时失败。错误消息如下所示。错误不是每次都发生,而是随机发生。我怀疑是由于内存分配失败。但是当程序运行时,我会监视系统RAM消耗,并且看不到RAM耗尽。有人有什么想法吗?

*** Process received signal ***
Signal: Segmentation fault (11)
Signal code: Address not mapped (1)
Failing at address: 0x96a5e64d
[ 0] [0xb770d40c]
[ 1] /lib/i386-linux-gnu/i686/cmov/libc.so.6(+0x7129e) [0xb732b29e]
[ 2] /lib/i386-linux-gnu/i686/cmov/libc.so.6(+0x73565) [0xb732d565]
[ 3] /lib/i386-linux-gnu/i686/cmov/libc.so.6(__libc_malloc+0x5c) [0xb732fa6c]
[ 4] /home/logia/work/projects/dev_Tao/products/mpitao/mpitao(_ZN9rapidjson12CrtAllocator6MallocEj+0x11) [0x809a7e5]
[ 5] /home/logia/work/projects/dev_Tao/products/mpitao/mpitao(_ZN9rapidjson19MemoryPoolAllocatorINS_12CrtAllocatorEE8AddChunkEj+0x1e) [0x80a4bf6]
[ 6] /home/logia/work/projects/dev_Tao/products/mpitao/mpitao(_ZN9rapidjson19MemoryPoolAllocatorINS_12CrtAllocatorEEC2EjPS1_+0x74) [0x80a2c6a]
[ 7] /home/logia/work/projects/dev_Tao/products/mpitao/mpitao(_ZN9rapidjson8internal5StackINS_19MemoryPoolAllocatorINS_12CrtAllocatorEEEEC2EPS4_j+0x9e) 

[ 8] /home/logia/work/projects/dev_Tao/products/mpitao/mpitao(_ZN9rapidjson6WriterINS_19GenericStringBufferINS_4UTF8IcEENS_12CrtAllocatorEEES3_NS_19MemoryPoolAllocatorIS4_EEEC2ERS5_PS7_j+0x2d) [0x809f255]
[ 9] /home/logia/work/projects/dev_Tao/products/mpitao/mpitao(_ZN6JMSG_C11get_msg_strEb+0x64) [0x809ad50]
[10] /home/logia/work/projects/dev_Tao/products/mpitao/mpitao(_Z9cell_mainR6COMM_C+0x7da) [0x80aba23]
[11] /home/logia/work/projects/dev_Tao/products/mpitao/mpitao(main+0xef)

[12] /lib/i386-linux-gnu/i686/cmov/libc.so.6(__libc_start_main+0xe6) 

0 个答案:

没有答案