libtorrent-rasterbar和QGuiApplication导致内存损坏 [英] Memory corruption with libtorrent-rasterbar and QGuiApplication

查看:122
本文介绍了libtorrent-rasterbar和QGuiApplication导致内存损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的Qt5应用程序中使用libtorrent,但始终会出现段错误 带有malloc()之类的消息:内存损坏.经过数小时的调试后,我想到了触发这一问题的一小段代码:

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()
}

在这种情况下,torrent_info的构造函数会产生segfault.但是,如果我在创建QGuiApplication之前像这样移动与libtorrent相关的代码:

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()
}

然后就可以了.同样,此问题仅在32位版本中存在,在64位版本中,两个变体的工作方式相同.

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

推荐答案

这很可能是由于使用一组TORRENT_ *定义构建libtorrent并使用另一组TORRENT_ *对其进行链接而引起的.其中一些定义影响公共API中使用的某些结构的布局,并且当调用应用程序与库之间存在差异时,会引入ABI不兼容问题.

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.

这篇关于libtorrent-rasterbar和QGuiApplication导致内存损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆