MsgPack 中的 free()/delete 不匹配

发布于 2024-11-25 09:59:04 字数 3010 浏览 1 评论 0原文

我尝试在我的程序中使用 Msgpack。 有人可以帮助我处理 msgpack wiki 中的下一个示例(流媒体功能): http:// wiki.msgpack.org/pages/viewpage.action?pageId=1081387 并提供使用此库与流功能的更正确的示例。

#include <msgpack.hpp> 
#include <iostream> 
#include <string> 

int main(void) { 
    // serializes multiple objects using msgpack::packer. 
    msgpack::sbuffer buffer; 

    msgpack::packer<msgpack::sbuffer> pk(&buffer); 
    pk.pack(std::string("Log message ... 1")); 
    pk.pack(std::string("Log message ... 2")); 
    pk.pack(std::string("Log message ... 3")); 

    // deserializes these objects using msgpack::unpacker. 
    msgpack::unpacker pac; 

    // feeds the buffer. 
    pac.reserve_buffer(buffer.size()); 
    memcpy(pac.buffer(), buffer.data(), buffer.size()); 
    pac.buffer_consumed(buffer.size()); 

    // now starts streaming deserialization. 
    msgpack::unpacked result; 
    while(pac.next(&result)) { 
        std::cout << result.get() << std::endl; 
    } 

    // results: 
    // $ g++ stream.cc -lmsgpack -o stream 
    // $ ./stream 
    // "Log message ... 1" 
    // "Log message ... 2" 
    // "Log message ... 3" 
}

Valgrind 说它有以下错误:

==11325== 1 errors in context 1 of 2:
==11325== Mismatched free() / delete / delete []
==11325==    at 0x48CC919: operator delete(void*) (vg_replace_malloc.c:387)
==11325==    by 0x804A623: std::auto_ptr<msgpack::zone>::reset(msgpack::zone*) (auto_ptr.h:242)
==11325==    by 0x804A2E1: msgpack::unpacker::next(msgpack::unpacked*) (unpack.hpp:229)
==11325==    by 0x8049E93: main (pack2.cpp:24)
==11325==  Address 0x6e447c0 is 0 bytes inside a block of size 8,220 alloc'd
==11325==    at 0x48CD876: malloc (vg_replace_malloc.c:236)
==11325==    by 0x48DABC9: msgpack_zone_new (zone.c:198)
==11325==    by 0x48D811F: msgpack_unpacker_release_zone (unpack.c:333)
==11325==    by 0x804A3DA: msgpack::unpacker::release_zone() (unpack.hpp:261)
==11325==    by 0x804A31C: msgpack::unpacker::next(msgpack::unpacked*) (unpack.hpp:234)
==11325==    by 0x8049E93: main (pack2.cpp:24)
==11325== 
==11325== 
==11325== 2 errors in context 2 of 2:
==11325== Mismatched free() / delete / delete []
==11325==    at 0x48CC919: operator delete(void*) (vg_replace_malloc.c:387)
==11325==    by 0x804A623: std::auto_ptr<msgpack::zone>::reset(msgpack::zone*) (auto_ptr.h:242)
==11325==    by 0x804A335: msgpack::unpacker::next(msgpack::unpacked*) (unpack.hpp:234)
==11325==    by 0x8049E93: main (pack2.cpp:24)
==11325==  Address 0x6e3c5c0 is 0 bytes inside a block of size 8,220 alloc'd
==11325==    at 0x48CD876: malloc (vg_replace_malloc.c:236)
==11325==    by 0x48DABC9: msgpack_zone_new (zone.c:198)
==11325==    by 0x48D8211: msgpack_unpacker_init (unpack.c:194)
==11325==    by 0x804A08D: msgpack::unpacker::unpacker(unsigned int) (unpack.hpp:187)
==11325==    by 0x8049DC5: main (pack2.cpp:15)

I try to use Msgpack in my program.
Can someone help me with next example (Streaming feature) from msgpack wiki: http://wiki.msgpack.org/pages/viewpage.action?pageId=1081387 and provide more correct example of using this library with streaming feature.

#include <msgpack.hpp> 
#include <iostream> 
#include <string> 

int main(void) { 
    // serializes multiple objects using msgpack::packer. 
    msgpack::sbuffer buffer; 

    msgpack::packer<msgpack::sbuffer> pk(&buffer); 
    pk.pack(std::string("Log message ... 1")); 
    pk.pack(std::string("Log message ... 2")); 
    pk.pack(std::string("Log message ... 3")); 

    // deserializes these objects using msgpack::unpacker. 
    msgpack::unpacker pac; 

    // feeds the buffer. 
    pac.reserve_buffer(buffer.size()); 
    memcpy(pac.buffer(), buffer.data(), buffer.size()); 
    pac.buffer_consumed(buffer.size()); 

    // now starts streaming deserialization. 
    msgpack::unpacked result; 
    while(pac.next(&result)) { 
        std::cout << result.get() << std::endl; 
    } 

    // results: 
    // $ g++ stream.cc -lmsgpack -o stream 
    // $ ./stream 
    // "Log message ... 1" 
    // "Log message ... 2" 
    // "Log message ... 3" 
}

Valgrind say that it has next errors:

==11325== 1 errors in context 1 of 2:
==11325== Mismatched free() / delete / delete []
==11325==    at 0x48CC919: operator delete(void*) (vg_replace_malloc.c:387)
==11325==    by 0x804A623: std::auto_ptr<msgpack::zone>::reset(msgpack::zone*) (auto_ptr.h:242)
==11325==    by 0x804A2E1: msgpack::unpacker::next(msgpack::unpacked*) (unpack.hpp:229)
==11325==    by 0x8049E93: main (pack2.cpp:24)
==11325==  Address 0x6e447c0 is 0 bytes inside a block of size 8,220 alloc'd
==11325==    at 0x48CD876: malloc (vg_replace_malloc.c:236)
==11325==    by 0x48DABC9: msgpack_zone_new (zone.c:198)
==11325==    by 0x48D811F: msgpack_unpacker_release_zone (unpack.c:333)
==11325==    by 0x804A3DA: msgpack::unpacker::release_zone() (unpack.hpp:261)
==11325==    by 0x804A31C: msgpack::unpacker::next(msgpack::unpacked*) (unpack.hpp:234)
==11325==    by 0x8049E93: main (pack2.cpp:24)
==11325== 
==11325== 
==11325== 2 errors in context 2 of 2:
==11325== Mismatched free() / delete / delete []
==11325==    at 0x48CC919: operator delete(void*) (vg_replace_malloc.c:387)
==11325==    by 0x804A623: std::auto_ptr<msgpack::zone>::reset(msgpack::zone*) (auto_ptr.h:242)
==11325==    by 0x804A335: msgpack::unpacker::next(msgpack::unpacked*) (unpack.hpp:234)
==11325==    by 0x8049E93: main (pack2.cpp:24)
==11325==  Address 0x6e3c5c0 is 0 bytes inside a block of size 8,220 alloc'd
==11325==    at 0x48CD876: malloc (vg_replace_malloc.c:236)
==11325==    by 0x48DABC9: msgpack_zone_new (zone.c:198)
==11325==    by 0x48D8211: msgpack_unpacker_init (unpack.c:194)
==11325==    by 0x804A08D: msgpack::unpacker::unpacker(unsigned int) (unpack.hpp:187)
==11325==    by 0x8049DC5: main (pack2.cpp:15)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

窝囊感情。 2024-12-02 09:59:04

看起来这个例子中一切都很好。根据 valgrind 调用跟踪,该错误位于 Msgpack 库内部。

Looks like everything is ok in this example. According to valgrind call traces, the bug is somewere inside Msgpack library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文