【问题标题】:Memory corruption with libtorrent-rasterbar and QGuiApplicationlibtorrent-rasterbar 和 QGuiApplication 导致内存损坏
【发布时间】:2013-11-24 18:16:24
【问题描述】:

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

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 的构造函数会产生段错误。但是如果我像这样在创建 QGuiApplication 之前移动 libtorrent 相关代码:

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 位版本中,两种变体的工作方式相同。

【问题讨论】:

    标签: qt libtorrent


    【解决方案1】:

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

    【讨论】:

    • 谢谢。在我的 CMakeLists.txt 中使用 pkg-config 中的 libtorrent 构建 cfalgs 后,问题就解决了。
    猜你喜欢
    • 1970-01-01
    • 2014-04-27
    • 1970-01-01
    • 1970-01-01
    • 2015-02-09
    • 1970-01-01
    • 1970-01-01
    • 2015-08-29
    • 2018-06-03
    相关资源
    最近更新 更多