mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-31 03:00:05 +00:00
TooltipWindow: Avoid potential use-after-free of lastComponentUnderMouse
Showing the tip will in turn call getDesktopScaleFactor(), accessing the lastComponentUnderMouse. In some cases, it was possible for lastComponentUnderMouse to point to a deleted component, resulting in UB. There are two changes in this PR: - Using a SafePointer rather than a raw pointer ensures that calls to getDesktopScaleFactor() will always be safe, regardless of when they happen. - Moving the assignment of lastComponentUnderMouse to before the call to displayTipInternal() ensures that the returned scale factor is that of the component that the mouse is currently hovering.
This commit is contained in:
parent
72fa2d98e1
commit
eb8a419ac7
2 changed files with 4 additions and 4 deletions
|
|
@ -218,6 +218,9 @@ void TooltipWindow::timerCallback()
|
|||
const auto tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
|
||||
const auto now = Time::getApproximateMillisecondCounter();
|
||||
|
||||
lastComponentUnderMouse = newComp;
|
||||
lastTipUnderMouse = newTip;
|
||||
|
||||
if (tipChanged || dismissalMouseEventOccurred || mouseMovedQuickly)
|
||||
lastCompChangeTime = now;
|
||||
|
||||
|
|
@ -246,9 +249,6 @@ void TooltipWindow::timerCallback()
|
|||
showTip();
|
||||
}
|
||||
}
|
||||
|
||||
lastComponentUnderMouse = newComp;
|
||||
lastTipUnderMouse = newTip;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ public:
|
|||
private:
|
||||
//==============================================================================
|
||||
Point<float> lastMousePos;
|
||||
Component* lastComponentUnderMouse = nullptr;
|
||||
SafePointer<Component> lastComponentUnderMouse;
|
||||
String tipShowing, lastTipUnderMouse, manuallyShownTip;
|
||||
int millisecondsBeforeTipAppears;
|
||||
unsigned int lastCompChangeTime = 0, lastHideTime = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue