-
Bug
-
Resolution: Done
-
P2: Important
-
4.6.1
-
None
-
a32c96e753c2f5a123e518a92762ec9c9ff3b0b7
The current implementation of QApplication::setInputContext is wrong:
void QApplication::setInputContext(QInputContext *inputContext)
{
Q_D(QApplication);
Q_UNUSED(d);// only static members being used.
if (!inputContext) {
qWarning("QApplication::setInputContext: called with 0 input context");
return;
}
delete d->inputContext;
d->inputContext = inputContext;
}
If d->inputContext already pointed to the same instance as inputContext, then it'll assign a dangling pointer to d->inputContext, which can easily crash the application.
So what's wrong:
- No guard against self-assignment,
- After calling delete, d->inputContext should be set to 0 (or, d->inputContext should be wrapped in a QPointer),
- Since QInputContext can be parented, it is questionable whether this setter should delete anything at all - The documentation does not mention this behaviour (to "replace" an object is not necessarily the same as destroying it).
(selected "text handling" since QInputContext is a text input helper)