[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    fix for KConfigPrivate::groupList (kconfig.cpp)
From:       Tommaso Massimi <tmassimi () gmail ! com>
Date:       2023-12-29 9:53:45
Message-ID: CAMd1qC4LGxoDODj30RB8L2+oSNNMzG-5akp5fhzk5jDe3uigcA () mail ! gmail ! com
[Download RAW message or body]

hi,

running plasma-systemmonitor with valgring a lot of problems are declared,
I'm trying to check them out.

I'm not sure if this is the best way to communicate with the development
team,
so I'm writing this mail also to have some indication about that. Please cc
me, I'm not subscribed to the list

part of valgrind output (neon unstable development 25-12-2023)

==70026== Invalid read of size 16
==70026==    at 0x668FAF7: ??? (in
/usr/lib/x86_64-linux-gnu/libQt6Core.so.6.6.1)
==70026==    by 0x575CB05: calculateHash<QStringView> (qhash.h:57)
==70026==    by 0x575CB05:
QHashPrivate::Data<QHashPrivate::Node<QStringView, QHashDummyValue>
>::findBucket(QStringView const&) const [clone .isra.0] (qhash.h:683)
==70026==    by 0x575FF43: findOrInsert (qhash.h:718)
==70026==    by 0x575FF43: QHash<QStringView, QHashDummyValue>::iterator
QHash<QStringView,
QHashDummyValue>::emplace_helper<QHashDummyValue>(QStringView&&,
QHashDummyValue&&) [clone .isra.0] (qhash.h:1335)
==70026==    by 0x5761E89: emplace<QHashDummyValue> (qhash.h:1321)
==70026==    by 0x5761E89: insert (qset.h:158)
==70026==    by 0x5761E89: operator() (kconfig.cpp:325)
==70026==    by 0x5761E89:
forEachEntryWhoseGroupStartsWith<KConfigPrivate::groupList(const QString&)
const::<lambda(KEntryMapConstIterator)> > (kconfigdata_p.h:252)
==70026==    by 0x5761E89: KConfigPrivate::groupList(QString const&) const
(kconfig.cpp:320)
==70026==    by 0x5771089: KConfigGroup::groupList() const
(kconfiggroup.cpp:1147)
==70026==    by 0x1B94F929: PageDataObject::load(KConfigBase const&,
QString const&) (PageDataObject.cpp:235)
==70026==    by 0x1B95705E: PagesModel::componentComplete()
(PagesModel.cpp:99)
==70026==    by 0x53C1876:
QQmlObjectCreator::finalize(QQmlInstantiationInterrupt&) (in
/usr/lib/x86_64-linux-gnu/libQt6Qml.so.6.6.1)
==70026==    by 0x54489AC:
QQmlComponentPrivate::complete(QQmlEnginePrivate*,
QQmlComponentPrivate::ConstructionState*) (in
/usr/lib/x86_64-linux-gnu/libQt6Qml.so.6.6.1)
==70026==    by 0x5448CAB: QQmlComponentPrivate::completeCreate() (in
/usr/lib/x86_64-linux-gnu/libQt6Qml.so.6.6.1)
==70026==    by 0x544AC88:
QQmlComponentPrivate::createWithProperties(QObject*, QMap<QString,
QVariant> const&, QQmlContext*, QQmlComponentPrivate::CreateBehavior) (in
/usr/lib/x86_64-linux-gnu/libQt6Qml.so.6.6.1)
==70026==    by 0x54400DF:
QQmlApplicationEnginePrivate::finishLoad(QQmlComponent*) (in
/usr/lib/x86_64-linux-gnu/libQt6Qml.so.6.6.1)
==70026==  Address 0xcd3c40a is 26 bytes inside a block of size 38 alloc'd
==70026==    at 0x4848899: malloc (in
/usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==70026==    by 0x65A5677: QArrayData::allocate(QArrayData**, long long,
long long, long long, QArrayData::AllocationOption) (in
/usr/lib/x86_64-linux-gnu/libQt6Core.so.6.6.1)
==70026==    by 0x657DCFE: QString::QString(long long, Qt::Initialization)
(in /usr/lib/x86_64-linux-gnu/libQt6Core.so.6.6.1)
==70026==    by 0x6589D97: QString::fromUtf8(QByteArrayView) (in
/usr/lib/x86_64-linux-gnu/libQt6Core.so.6.6.1)
==70026==    by 0x577DA4E: fromUtf8<> (qstring.h:588)
==70026==    by 0x577DA4E: KConfigIniBackend::parseConfig(QByteArray
const&, KEntryMap&, QFlags<KConfigBackend::ParseOption>, bool)
(kconfigini.cpp:157)
==70026==    by 0x5760C68: KConfigPrivate::parseConfigFiles()
(kconfig.cpp:798)
==70026==    by 0x5784E81: KSharedConfig::KSharedConfig(QString const&,
QFlags<KConfig::OpenFlag>, QStandardPaths::StandardLocation)
(ksharedconfig.cpp:123)
==70026==    by 0x57854E0: KSharedConfig::openConfig(QString const&,
QFlags<KConfig::OpenFlag>, QStandardPaths::StandardLocation)
(ksharedconfig.cpp:88)
==70026==    by 0x1B957006: PagesModel::componentComplete()
(PagesModel.cpp:96)
==70026==    by 0x53C1876:
QQmlObjectCreator::finalize(QQmlInstantiationInterrupt&) (in
/usr/lib/x86_64-linux-gnu/libQt6Qml.so.6.6.1)
==70026==    by 0x54489AC:
QQmlComponentPrivate::complete(QQmlEnginePrivate*,
QQmlComponentPrivate::ConstructionState*) (in
/usr/lib/x86_64-linux-gnu/libQt6Qml.so.6.6.1)
==70026==    by 0x5448CAB: QQmlComponentPrivate::completeCreate() (in
/usr/lib/x86_64-linux-gnu/libQt6Qml.so.6.6.1)



this problem is generated in this function:


==70026==    by 0x5761E89: KConfigPrivate::groupList(QString const&) const
(kconfig.cpp:320)

i.e.

QStringList KConfigPrivate::groupList(const QString &groupName) const
{
    const QString theGroup = groupName + QLatin1Char('\x1d');
    QSet<QStringView> groups;

    entryMap.forEachEntryWhoseGroupStartsWith(theGroup, [&theGroup,
&groups](KEntryMapConstIterator entryMapIt) {
        if (isNonDeletedKey(entryMapIt)) {
            const QString &entryGroup = entryMapIt->first.mGroup;
            const auto subgroupStartPos = theGroup.size();
            const auto subgroupEndPos = findFirstGroupEndPos(entryGroup,
subgroupStartPos);
            groups.insert(QStringView(entryGroup).mid(subgroupStartPos,
subgroupEndPos - subgroupStartPos));
        }
    });

    return stringListFromStringViewCollection(groups);
}



in this line the function .mid (deprecated in QStringView) is creating a
temporary object which is inserted to groups,

            groups.insert(QStringView(entryGroup).mid(subgroupStartPos,
subgroupEndPos - subgroupStartPos));


groups is declared as :
QSet<QStringView> groups;

QStringView doesn't own data, it is like a wrapper/reference to a qstring.
so the value inserted on group is like a reference to a temporary qstring;
but the qstring will be deleted while the QStringView will remain in group
pointing to garbage


==================

this is my correction, no more complaints from valgrind about this case



tom1@tom-neon:~/kde/src/kconfig/src/core$ git diff kconfig.cpp
diff --git a/src/core/kconfig.cpp b/src/core/kconfig.cpp
index b467e17e..31be6845 100644
--- a/src/core/kconfig.cpp
+++ b/src/core/kconfig.cpp
@@ -315,18 +315,19 @@ QStringList KConfig::groupList() const
 QStringList KConfigPrivate::groupList(const QString &groupName) const
 {
     const QString theGroup = groupName + QLatin1Char('\x1d');
-    QSet<QStringView> groups;
+    QSet<QString> groups;

     entryMap.forEachEntryWhoseGroupStartsWith(theGroup, [&theGroup,
&groups](KEntryMapConstIterator entryMapIt) {
         if (isNonDeletedKey(entryMapIt)) {
             const QString &entryGroup = entryMapIt->first.mGroup;
             const auto subgroupStartPos = theGroup.size();
             const auto subgroupEndPos = findFirstGroupEndPos(entryGroup,
subgroupStartPos);
-            groups.insert(QStringView(entryGroup).mid(subgroupStartPos,
subgroupEndPos - subgroupStartPos));
+            groups.insert(entryGroup.mid(subgroupStartPos, subgroupEndPos
- subgroupStartPos));
         }
     });

-    return stringListFromStringViewCollection(groups);
+    QStringList list(groups.begin(), groups.end());
+    return list;
 }

[Attachment #3 (text/html)]

<div dir="ltr">hi,<br><br>running plasma-systemmonitor with valgring a lot of \
problems are declared,<br>I&#39;m trying to check them out.<br><br>I&#39;m not sure \
if this is the best way to communicate with the development team,<br>so I&#39;m \
writing this mail also to have some indication about that. Please cc me, I&#39;m not \
subscribed to the list<br><br>part of valgrind output (neon unstable development \
25-12-2023)<br><br>==70026== Invalid read of size 16<br>==70026==      at 0x668FAF7: \
??? (in /usr/lib/x86_64-linux-gnu/libQt6Core.so.6.6.1)<br>==70026==      by \
0x575CB05: calculateHash&lt;QStringView&gt; (qhash.h:57)<br>==70026==      by \
0x575CB05: QHashPrivate::Data&lt;QHashPrivate::Node&lt;QStringView, \
QHashDummyValue&gt; &gt;::findBucket(QStringView const&amp;) const [clone .isra.0] \
(qhash.h:683)<br>==70026==      by 0x575FF43: findOrInsert (qhash.h:718)<br>==70026== \
by 0x575FF43: QHash&lt;QStringView, QHashDummyValue&gt;::iterator \
QHash&lt;QStringView, \
QHashDummyValue&gt;::emplace_helper&lt;QHashDummyValue&gt;(QStringView&amp;&amp;, \
QHashDummyValue&amp;&amp;) [clone .isra.0] (qhash.h:1335)<br>==70026==      by \
0x5761E89: emplace&lt;QHashDummyValue&gt; (qhash.h:1321)<br>==70026==      by \
0x5761E89: insert (qset.h:158)<br>==70026==      by 0x5761E89: operator() \
(kconfig.cpp:325)<br>==70026==      by 0x5761E89: \
forEachEntryWhoseGroupStartsWith&lt;KConfigPrivate::groupList(const QString&amp;) \
const::&lt;lambda(KEntryMapConstIterator)&gt; &gt; (kconfigdata_p.h:252)<br>==70026== \
by 0x5761E89: KConfigPrivate::groupList(QString const&amp;) const \
(kconfig.cpp:320)<br>==70026==      by 0x5771089: KConfigGroup::groupList() const \
(kconfiggroup.cpp:1147)<br>==70026==      by 0x1B94F929: \
PageDataObject::load(KConfigBase const&amp;, QString const&amp;) \
(PageDataObject.cpp:235)<br>==70026==      by 0x1B95705E: \
PagesModel::componentComplete() (PagesModel.cpp:99)<br>==70026==      by 0x53C1876: \
QQmlObjectCreator::finalize(QQmlInstantiationInterrupt&amp;) (in \
/usr/lib/x86_64-linux-gnu/libQt6Qml.so.6.6.1)<br>==70026==      by 0x54489AC: \
QQmlComponentPrivate::complete(QQmlEnginePrivate*, \
QQmlComponentPrivate::ConstructionState*) (in \
/usr/lib/x86_64-linux-gnu/libQt6Qml.so.6.6.1)<br>==70026==      by 0x5448CAB: \
QQmlComponentPrivate::completeCreate() (in \
/usr/lib/x86_64-linux-gnu/libQt6Qml.so.6.6.1)<br>==70026==      by 0x544AC88: \
QQmlComponentPrivate::createWithProperties(QObject*, QMap&lt;QString, QVariant&gt; \
const&amp;, QQmlContext*, QQmlComponentPrivate::CreateBehavior) (in \
/usr/lib/x86_64-linux-gnu/libQt6Qml.so.6.6.1)<br>==70026==      by 0x54400DF: \
QQmlApplicationEnginePrivate::finishLoad(QQmlComponent*) (in \
/usr/lib/x86_64-linux-gnu/libQt6Qml.so.6.6.1)<br>==70026==   Address 0xcd3c40a is 26 \
bytes inside a block of size 38 alloc&#39;d<br>==70026==      at 0x4848899: malloc \
(in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)<br>==70026==      by \
0x65A5677: QArrayData::allocate(QArrayData**, long long, long long, long long, \
QArrayData::AllocationOption) (in \
/usr/lib/x86_64-linux-gnu/libQt6Core.so.6.6.1)<br>==70026==      by 0x657DCFE: \
QString::QString(long long, Qt::Initialization) (in \
/usr/lib/x86_64-linux-gnu/libQt6Core.so.6.6.1)<br>==70026==      by 0x6589D97: \
QString::fromUtf8(QByteArrayView) (in \
/usr/lib/x86_64-linux-gnu/libQt6Core.so.6.6.1)<br>==70026==      by 0x577DA4E: \
fromUtf8&lt;&gt; (qstring.h:588)<br>==70026==      by 0x577DA4E: \
KConfigIniBackend::parseConfig(QByteArray const&amp;, KEntryMap&amp;, \
QFlags&lt;KConfigBackend::ParseOption&gt;, bool) (kconfigini.cpp:157)<br>==70026==    \
by 0x5760C68: KConfigPrivate::parseConfigFiles() (kconfig.cpp:798)<br>==70026==      \
by 0x5784E81: KSharedConfig::KSharedConfig(QString const&amp;, \
QFlags&lt;KConfig::OpenFlag&gt;, QStandardPaths::StandardLocation) \
(ksharedconfig.cpp:123)<br>==70026==      by 0x57854E0: \
KSharedConfig::openConfig(QString const&amp;, QFlags&lt;KConfig::OpenFlag&gt;, \
QStandardPaths::StandardLocation) (ksharedconfig.cpp:88)<br>==70026==      by \
0x1B957006: PagesModel::componentComplete() (PagesModel.cpp:96)<br>==70026==      by \
0x53C1876: QQmlObjectCreator::finalize(QQmlInstantiationInterrupt&amp;) (in \
/usr/lib/x86_64-linux-gnu/libQt6Qml.so.6.6.1)<br>==70026==      by 0x54489AC: \
QQmlComponentPrivate::complete(QQmlEnginePrivate*, \
QQmlComponentPrivate::ConstructionState*) (in \
/usr/lib/x86_64-linux-gnu/libQt6Qml.so.6.6.1)<br>==70026==      by 0x5448CAB: \
QQmlComponentPrivate::completeCreate() (in \
/usr/lib/x86_64-linux-gnu/libQt6Qml.so.6.6.1)<br><br><br><br>this problem is \
generated in this function:<br><br><br>==70026==      by 0x5761E89: \
KConfigPrivate::groupList(QString const&amp;) const \
(kconfig.cpp:320)<br><br>i.e.<br><br>QStringList KConfigPrivate::groupList(const \
QString &amp;groupName) const<br>{<br>      const QString theGroup = groupName + \
QLatin1Char(&#39;\x1d&#39;);<br>      QSet&lt;QStringView&gt; groups;<br><br>      \
entryMap.forEachEntryWhoseGroupStartsWith(theGroup, [&amp;theGroup, \
&amp;groups](KEntryMapConstIterator entryMapIt) {<br>            if \
(isNonDeletedKey(entryMapIt)) {<br>                  const QString &amp;entryGroup = \
entryMapIt-&gt;first.mGroup;<br>                  const auto subgroupStartPos = \
theGroup.size();<br>                  const auto subgroupEndPos = \
findFirstGroupEndPos(entryGroup, subgroupStartPos);<br>                  \
groups.insert(QStringView(entryGroup).mid(subgroupStartPos, subgroupEndPos - \
subgroupStartPos));<br>            }<br>      });<br><br>      return \
stringListFromStringViewCollection(groups);<br>}<br><br><br><br>in this line the \
function .mid (deprecated in QStringView) is creating a temporary object which is \
inserted to groups,<br><br>                  \
groups.insert(QStringView(entryGroup).mid(subgroupStartPos, subgroupEndPos - \
subgroupStartPos));<br><br><br>groups is declared as :<br>QSet&lt;QStringView&gt; \
groups;<br><br>QStringView doesn&#39;t own data, it is like a wrapper/reference to a \
qstring.<br>so the value inserted on group is like a reference to a temporary \
qstring; but the qstring will be deleted while the QStringView will remain in group \
pointing to garbage<br><br><br>==================<br><br>this is my correction, no \
more complaints from valgrind about this \
case<br><br><br><br>tom1@tom-neon:~/kde/src/kconfig/src/core$ git diff \
kconfig.cpp<br>diff --git a/src/core/kconfig.cpp b/src/core/kconfig.cpp<br>index \
b467e17e..31be6845 100644<br>--- a/src/core/kconfig.cpp<br>+++ \
b/src/core/kconfig.cpp<br>@@ -315,18 +315,19 @@ QStringList KConfig::groupList() \
const<br>  QStringList KConfigPrivate::groupList(const QString &amp;groupName) \
const<br>  {<br>        const QString theGroup = groupName + \
QLatin1Char(&#39;\x1d&#39;);<br>-      QSet&lt;QStringView&gt; groups;<br>+      \
QSet&lt;QString&gt; groups;<br><br>        \
entryMap.forEachEntryWhoseGroupStartsWith(theGroup, [&amp;theGroup, \
&amp;groups](KEntryMapConstIterator entryMapIt) {<br>              if \
(isNonDeletedKey(entryMapIt)) {<br>                    const QString &amp;entryGroup \
= entryMapIt-&gt;first.mGroup;<br>                    const auto subgroupStartPos = \
theGroup.size();<br>                    const auto subgroupEndPos = \
findFirstGroupEndPos(entryGroup, subgroupStartPos);<br>-                  \
groups.insert(QStringView(entryGroup).mid(subgroupStartPos, subgroupEndPos - \
subgroupStartPos));<br>+                  \
groups.insert(entryGroup.mid(subgroupStartPos, subgroupEndPos - \
subgroupStartPos));<br>              }<br>        });<br><br>-      return \
stringListFromStringViewCollection(groups);<br>+      QStringList \
list(groups.begin(), groups.end());<br>+      return list;<br>  \
}<br><br><br><br><br><br></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic