c_str() of an rvalue - unsafe?
<p>Could anyone explain why the following crashes with an access violation at <code>0xFFFFFFFF</code> at <code>avformat_open_input</code>?</p>

<pre><code>std::string u8(const std::wstring&amp; str)
{
    return boost::locale::conv::utf_to_utf&lt;char&gt;(str);
}

AVFormatContext* open_input(const std::wstring&amp; filename)
{
    AVFormatContext* context = nullptr;
    avformat_open_input(&amp;context, u8(filename).c_str(), nullptr, nullptr);
    avformat_find_stream_info(context, nullptr);
    return context;
}
</code></pre>

<p>while the following works:</p>

<pre><code>AVFormatContext* open_input(const std::wstring&amp; filename)
{
    auto u8filename = u8(filename);
    AVFormatContext* context = nullptr;
    avformat_open_input(&amp;context, u8filename.c_str(), nullptr, nullptr);        
    avformat_find_stream_info(context, nullptr);
    return context;
}
</code></pre>
