Memory corruption with libtorrent-rasterbar and QGuiApplication

元气小坏坏 提交于 2019-12-13 04:51:28

问题


I'm trying to use libtorrent in my Qt5 application but keep getting segfaults with messages like malloc(): memory corruption. After hours of debbuging I come up with this small piece of code which triggers this problem:

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    std::string filename = "fedora.torrent";
    libtorrent::error_code ec;
    libtorrent::add_torrent_params parameters;
    std::cerr << "111\n";
    parameters.ti = new libtorrent::torrent_info(filename, ec);;
    std::cerr << "222\n";
    return app.exec()
}

In this case constructor of torrent_info produce segfault. But if I move libtorrent related code before creation of QGuiApplication like this:

int main(int argc, char *argv[])
{
    std::string filename = "fedora.torrent";
    libtorrent::error_code ec;
    libtorrent::add_torrent_params parameters;
    std::cerr << "111\n";
    parameters.ti = new libtorrent::torrent_info(filename, ec);;
    std::cerr << "222\n";
    QGuiApplication app(argc, argv);
    return app.exec()
}

then it works just fine. Also this problem exist only in 32-bit build, in 64-bit build both variants work the same.


回答1:


This is most likely caused by building libtorrent with one set of TORRENT_* defines and linking against it with a different set. Some of those defines affect layouts of some structs used in the public API and when differing between the calling application and the library introduce ABI incompatibility issues.



来源:https://stackoverflow.com/questions/20178064/memory-corruption-with-libtorrent-rasterbar-and-qguiapplication

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!