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.
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.