diff --git a/bindings/python/src/magnet_uri.cpp b/bindings/python/src/magnet_uri.cpp index 610626d9d..83ba4a4f3 100644 --- a/bindings/python/src/magnet_uri.cpp +++ b/bindings/python/src/magnet_uri.cpp @@ -12,7 +12,8 @@ using namespace boost::python; using namespace libtorrent; extern void dict_to_add_torrent_params(dict params - , add_torrent_params& p, std::vector& rd); + , add_torrent_params& p, std::vector& rd + , std::list& storage); namespace { @@ -21,7 +22,8 @@ namespace { add_torrent_params p; std::vector resume_buf; - dict_to_add_torrent_params(params, p, resume_buf); + std::list string_storage; + dict_to_add_torrent_params(params, p, resume_buf, string_storage); #ifndef BOOST_NO_EXCEPTIONS return add_magnet_uri(s, uri, p); diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index 94cc075ab..80ab0719e 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -2,6 +2,8 @@ // subject to the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +#include +#include #include #include #include // for bencode_map_entry @@ -145,7 +147,8 @@ namespace #endif } - void dict_to_add_torrent_params(dict params, add_torrent_params& p, std::vector& rd) + void dict_to_add_torrent_params(dict params, add_torrent_params& p + , std::vector& rd, std::list& string_storage) { // torrent_info objects are always held by an intrusive_ptr in the python binding if (params.has_key("ti")) @@ -154,16 +157,15 @@ namespace std::string url; if (params.has_key("tracker_url")) { - url = extract(params["tracker_url"]); - p.tracker_url = url.c_str(); + string_storage.push_back(extract(params["tracker_url"])); + p.tracker_url = string_storage.back().c_str(); } if (params.has_key("info_hash")) p.info_hash = extract(params["info_hash"]); - std::string name; if (params.has_key("name")) { - name = extract(params["name"]); - p.name = name.c_str(); + string_storage.push_back(extract(params["name"])); + p.name = string_storage.back().c_str(); } p.save_path = extract(params["save_path"]); @@ -217,7 +219,8 @@ namespace { add_torrent_params p; std::vector resume_buf; - dict_to_add_torrent_params(params, p, resume_buf); + std::list string_buf; + dict_to_add_torrent_params(params, p, resume_buf, string_buf); allow_threading_guard guard; @@ -229,7 +232,9 @@ namespace #endif } - void dict_to_feed_settings(dict params, feed_settings& feed, std::vector& resume_buf) + void dict_to_feed_settings(dict params, feed_settings& feed + , std::vector& resume_buf + , std::list& string_storage) { if (params.has_key("auto_download")) feed.auto_download = extract(params["auto_download"]); @@ -238,7 +243,8 @@ namespace if (params.has_key("url")) feed.url = extract(params["url"]); if (params.has_key("add_args")) - dict_to_add_torrent_params(dict(params["add_args"]), feed.add_args, resume_buf); + dict_to_add_torrent_params(dict(params["add_args"]), feed.add_args + , resume_buf, string_storage); } feed_handle add_feed(session& s, dict params) @@ -249,7 +255,8 @@ namespace // this static here is a bit of a hack. It will // probably work for the most part static std::vector resume_buf; - dict_to_feed_settings(params, feed, resume_buf); + std::list string_storage; + dict_to_feed_settings(params, feed, resume_buf, string_storage); return s.add_feed(feed); } @@ -295,7 +302,8 @@ namespace feed_settings feed; static std::vector resume_buf; - dict_to_feed_settings(sett, feed, resume_buf); + std::list string_storage; + dict_to_feed_settings(sett, feed, resume_buf, string_storage); h.set_settings(feed); }