invalid memory read selecting from a combo box (qt)

Started by ajschult, December 01, 2012, 05:01:08 PM

Previous topic - Next topic

ajschult

I loaded up fatkid.flv under valgrind and selected something from a dropdown menu in the GUI (audio and video codec dropdowns both trigger this).  After selecting an element from the list, valgrind complains:


Invalid read of size 1
   at 0x4A09DE1: __GI_strcmp (mc_replace_strmem.c:730)
   by 0x46321F: MainWindow::comboChanged(int) (Q_gui2.cpp:129)
   by 0x34E978E71E: QMetaObject::activate(QObject*, QMetaObject const*, int, void**) (qobject.cpp:3547)
   by 0x34EEF9B9C0: QComboBox::activated(int) (moc_qcombobox.cpp:287)
   by 0x34EEF9BA40: QComboBoxPrivate::emitActivated(QModelIndex const&) (qcombobox.cpp:1261)
   by 0x34EEF9CAF6: QComboBoxPrivate::_q_itemSelected(QModelIndex const&) (qcombobox.cpp:1252)
Address 0x21d67e18 is 24 bytes inside a block of size 45 free'd
   at 0x4A07786: free (vg_replace_malloc.c:446)
   by 0x4692CE: QByteArray::~QByteArray() (in /build/andrew/avidemux/avidemux_2.6.0/buildQt4/avidemux3_qt4)
   by 0x463202: MainWindow::comboChanged(int) (Q_gui2.cpp:127)
   by 0x34E978E71E: QMetaObject::activate(QObject*, QMetaObject const*, int, void**) (qobject.cpp:3547)
   by 0x34EEF9B9C0: QComboBox::activated(int) (moc_qcombobox.cpp:287)
   by 0x34EEF9BA40: QComboBoxPrivate::emitActivated(QModelIndex const&) (qcombobox.cpp:1261)

Invalid read of size 1
   at 0x4A09DF8: __GI_strcmp (mc_replace_strmem.c:730)
   by 0x46321F: MainWindow::comboChanged(int) (Q_gui2.cpp:129)
   by 0x34E978E71E: QMetaObject::activate(QObject*, QMetaObject const*, int, void**) (qobject.cpp:3547)
   by 0x34EEF9B9C0: QComboBox::activated(int) (moc_qcombobox.cpp:287)
   by 0x34EEF9BA40: QComboBoxPrivate::emitActivated(QModelIndex const&) (qcombobox.cpp:1261)
   by 0x34EEF9CAF6: QComboBoxPrivate::_q_itemSelected(QModelIndex const&) (qcombobox.cpp:1252)
Address 0x21d67e19 is 25 bytes inside a block of size 45 free'd
   at 0x4A07786: free (vg_replace_malloc.c:446)
   by 0x4692CE: QByteArray::~QByteArray() (in /build/andrew/avidemux/avidemux_2.6.0/buildQt4/avidemux3_qt4)
   by 0x463202: MainWindow::comboChanged(int) (Q_gui2.cpp:127)
   by 0x34E978E71E: QMetaObject::activate(QObject*, QMetaObject const*, int, void**) (qobject.cpp:3547)
   by 0x34EEF9B9C0: QComboBox::activated(int) (moc_qcombobox.cpp:287)
   by 0x34EEF9BA40: QComboBoxPrivate::emitActivated(QModelIndex const&) (qcombobox.cpp:1261)

ajschult

http://doc.qt.digia.com/qt/qtglobal.html#qPrintable

Quote
Returns str as a const char *. This is equivalent to str.toLocal8Bit().constData().

The char pointer will be invalid after the statement in which qPrintable() is used. This is because the array returned by toLocal8Bit() will fall out of scope.

this seems to work:


-const char *source=qPrintable(sender()->objectName());
+QByteArray ba = sender()->objectName().toLocal8Bit();
+const char *source=ba.constData();

gruntster