diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index cf38a90151b..a0b8432b5b3 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -1338,11 +1338,8 @@ void QMessagePattern::setPattern(const QString &pattern) .arg(lexeme); } } else { - char *literal = new char[lexeme.size() + 1]; - strncpy(literal, lexeme.toLatin1().constData(), lexeme.size()); - literal[lexeme.size()] = '\0'; - literalsVar.emplace_back(literal); - tokens[i] = literal; + using UP = std::unique_ptr; + tokens[i] = literalsVar.emplace_back(UP(qstrdup(lexeme.toLatin1().constData()))).get(); } } if (nestedIfError)