• Romain Vimont's avatar
    gui/qt: bookmarks: fix psz_name lifetime · ea0a32e1
    Romain Vimont authored
    The macro qtu() is defined as follows:
        #define qtu( i ) ((i).toUtf8().constData())
    "i" is a QString, .toUtf8() returns a QByteArray, .constData() returns a
    pointer to the data inside the QByteArray.
    It is important to notice that the QByteArray is temporary. Therefore,
    it is "destroyed as the last step in evaluating the full-expression that
    (lexically) contains the point where [it was] created".
    Concretely, this means that this call is correct:
        do_something( qtu( string ) );
    But this one is undefined behavior:
        const char *s = qtu( string );
        do_something( s );
    Thus, here, bookmark.psz_name was initialized with a pointer to garbage
    To fix the problem, store the QByteArray in a local variable so that it
    lives long enough.
    (Fixes invalid reads reported by valgrind)
    Signed-off-by: Romain Vimont's avatarRomain Vimont <rom@rom1v.com>
    Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
bookmarks.cpp 9.71 KB