libtorrent-rasterbar 和 QGuiApplication 导致内存损坏

Posted

技术标签:

【中文标题】libtorrent-rasterbar 和 QGuiApplication 导致内存损坏【英文标题】:Memory corruption with libtorrent-rasterbar and 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 位版本中,两种变体的工作方式相同。

【问题讨论】:

【参考方案1】:

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

【讨论】:

谢谢。在我的 CMakeLists.txt 中使用 pkg-config 中的 libtorrent 构建 cfalgs 后,问题就解决了。

以上是关于libtorrent-rasterbar 和 QGuiApplication 导致内存损坏的主要内容,如果未能解决你的问题,请参考以下文章

libtorrent-rasterbar 的 Python 绑定不起作用

libtorrent-rasterbar 的 python 绑定是不是适用于 Python 3?

导入 libtorrent 不工作

恒源云(GpuShare)_无监督的QG方法

恒源云(GpuShare)_无监督的QG方法

com.alibaba.otter.canal.client.impl.ServerNotFoundException: no alive canal server for ucs_sf_to_qg_