Skip to content

Commit f5d2d85

Browse files
committed
QgsXmlUtils::readFlagAttribute(): fix use-after-free
Found with Valgrind ```const char* c_str = qstr.toUtf8().data()``` is invalid since the QByteArray returned by toUtf8() is destroyed at the end of the expression, letting c_str point to freed memory On the contrary ```foo(qstr.toUtf8().data())``` is valid since the temporary object is destroyed only after foo invokation.
1 parent 81db005 commit f5d2d85

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/core/qgsxmlutils.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ class CORE_EXPORT QgsXmlUtils
9797
if ( metaEnum.isValid() )
9898
{
9999
bool ok = false;
100-
const char *vs = sourceCategoriesStr.toUtf8().data();
101-
int newValue = metaEnum.keysToValue( vs, &ok );
100+
int newValue = metaEnum.keysToValue( sourceCategoriesStr.toUtf8().data(), &ok );
102101
if ( ok )
103102
value = static_cast<T>( newValue );
104103
}

0 commit comments

Comments
 (0)