UI: Use QScopedPointer (not QPointer) where applicable
Contrary to what the name would have you believe, QPointer<> is not used to delete a pointer when it leaves its specific scope. Instead, it's used to check to see if the pointer is still valid. For most QWidget-based objects, this is actually fine because QWidgets that are assigned to layouts or other widgets will automatically be destroyed -- however, for non-widget objects, this can cause a memory leak. This patch replaces QPointer with QScopedPointer where applicable to prevent memory leaks. Closes obsproject/obs-studio#1367master
parent
a5d740373c
commit
b6665f9cc0
|
@ -569,7 +569,7 @@ static bool QueryRemove(QWidget *parent, obs_source_t *source)
|
||||||
|
|
||||||
void OBSBasicFilters::on_addAsyncFilter_clicked()
|
void OBSBasicFilters::on_addAsyncFilter_clicked()
|
||||||
{
|
{
|
||||||
QPointer<QMenu> popup = CreateAddFilterPopupMenu(true);
|
QScopedPointer<QMenu> popup(CreateAddFilterPopupMenu(true));
|
||||||
if (popup)
|
if (popup)
|
||||||
popup->exec(QCursor::pos());
|
popup->exec(QCursor::pos());
|
||||||
}
|
}
|
||||||
|
@ -611,7 +611,7 @@ void OBSBasicFilters::on_asyncFilters_currentRowChanged(int row)
|
||||||
|
|
||||||
void OBSBasicFilters::on_addEffectFilter_clicked()
|
void OBSBasicFilters::on_addEffectFilter_clicked()
|
||||||
{
|
{
|
||||||
QPointer<QMenu> popup = CreateAddFilterPopupMenu(false);
|
QScopedPointer<QMenu> popup(CreateAddFilterPopupMenu(false));
|
||||||
if (popup)
|
if (popup)
|
||||||
popup->exec(QCursor::pos());
|
popup->exec(QCursor::pos());
|
||||||
}
|
}
|
||||||
|
|
|
@ -750,7 +750,7 @@ void OBSBasic::CreateProgramOptions()
|
||||||
programOptions->setLayout(layout);
|
programOptions->setLayout(layout);
|
||||||
|
|
||||||
auto onAdd = [this] () {
|
auto onAdd = [this] () {
|
||||||
QPointer<QMenu> menu = CreateTransitionMenu(this, nullptr);
|
QScopedPointer<QMenu> menu(CreateTransitionMenu(this, nullptr));
|
||||||
menu->exec(QCursor::pos());
|
menu->exec(QCursor::pos());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -233,7 +233,7 @@ OBSBasic::OBSBasic(QWidget *parent)
|
||||||
|
|
||||||
cpuUsageInfo = os_cpu_usage_info_start();
|
cpuUsageInfo = os_cpu_usage_info_start();
|
||||||
cpuUsageTimer = new QTimer(this);
|
cpuUsageTimer = new QTimer(this);
|
||||||
connect(cpuUsageTimer, SIGNAL(timeout()),
|
connect(cpuUsageTimer.data(), SIGNAL(timeout()),
|
||||||
ui->statusbar, SLOT(UpdateCPUUsage()));
|
ui->statusbar, SLOT(UpdateCPUUsage()));
|
||||||
cpuUsageTimer->start(3000);
|
cpuUsageTimer->start(3000);
|
||||||
|
|
||||||
|
@ -1694,7 +1694,7 @@ void OBSBasic::OnFirstLoad()
|
||||||
this, &OBSBasic::ReceivedIntroJson);
|
this, &OBSBasic::ReceivedIntroJson);
|
||||||
}
|
}
|
||||||
if (wnit) {
|
if (wnit) {
|
||||||
introCheckThread = wnit;
|
introCheckThread.reset(wnit);
|
||||||
introCheckThread->start();
|
introCheckThread->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2852,7 +2852,7 @@ void OBSBasic::CheckForUpdates(bool manualUpdate)
|
||||||
if (updateCheckThread && updateCheckThread->isRunning())
|
if (updateCheckThread && updateCheckThread->isRunning())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
updateCheckThread = new AutoUpdateThread(manualUpdate);
|
updateCheckThread.reset(new AutoUpdateThread(manualUpdate));
|
||||||
updateCheckThread->start();
|
updateCheckThread->start();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -4227,7 +4227,7 @@ void OBSBasic::AddSourcePopupMenu(const QPoint &pos)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointer<QMenu> popup = CreateAddSourcePopupMenu();
|
QScopedPointer<QMenu> popup(CreateAddSourcePopupMenu());
|
||||||
if (popup)
|
if (popup)
|
||||||
popup->exec(pos);
|
popup->exec(pos);
|
||||||
}
|
}
|
||||||
|
@ -4381,14 +4381,13 @@ void OBSBasic::UploadLog(const char *subdir, const char *file)
|
||||||
|
|
||||||
if (logUploadThread) {
|
if (logUploadThread) {
|
||||||
logUploadThread->wait();
|
logUploadThread->wait();
|
||||||
delete logUploadThread;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteTextThread *thread = new RemoteTextThread(
|
RemoteTextThread *thread = new RemoteTextThread(
|
||||||
"https://obsproject.com/logs/upload",
|
"https://obsproject.com/logs/upload",
|
||||||
"text/plain", ss.str().c_str());
|
"text/plain", ss.str().c_str());
|
||||||
|
|
||||||
logUploadThread = thread;
|
logUploadThread.reset(thread);
|
||||||
connect(thread, &RemoteTextThread::Result,
|
connect(thread, &RemoteTextThread::Result,
|
||||||
this, &OBSBasic::logUploadFinished);
|
this, &OBSBasic::logUploadFinished);
|
||||||
logUploadThread->start();
|
logUploadThread->start();
|
||||||
|
@ -6143,25 +6142,26 @@ void OBSBasic::ToggleShowHide()
|
||||||
|
|
||||||
void OBSBasic::SystemTrayInit()
|
void OBSBasic::SystemTrayInit()
|
||||||
{
|
{
|
||||||
trayIcon = new QSystemTrayIcon(QIcon(":/res/images/obs.png"),
|
trayIcon.reset(new QSystemTrayIcon(QIcon(":/res/images/obs.png"),
|
||||||
this);
|
this));
|
||||||
trayIcon->setToolTip("OBS Studio");
|
trayIcon->setToolTip("OBS Studio");
|
||||||
|
|
||||||
showHide = new QAction(QTStr("Basic.SystemTray.Show"),
|
showHide = new QAction(QTStr("Basic.SystemTray.Show"),
|
||||||
trayIcon);
|
trayIcon.data());
|
||||||
sysTrayStream = new QAction(QTStr("Basic.Main.StartStreaming"),
|
sysTrayStream = new QAction(QTStr("Basic.Main.StartStreaming"),
|
||||||
trayIcon);
|
trayIcon.data());
|
||||||
sysTrayRecord = new QAction(QTStr("Basic.Main.StartRecording"),
|
sysTrayRecord = new QAction(QTStr("Basic.Main.StartRecording"),
|
||||||
trayIcon);
|
trayIcon.data());
|
||||||
sysTrayReplayBuffer = new QAction(QTStr("Basic.Main.StartReplayBuffer"),
|
sysTrayReplayBuffer = new QAction(QTStr("Basic.Main.StartReplayBuffer"),
|
||||||
trayIcon);
|
trayIcon.data());
|
||||||
exit = new QAction(QTStr("Exit"),
|
exit = new QAction(QTStr("Exit"),
|
||||||
trayIcon);
|
trayIcon.data());
|
||||||
|
|
||||||
if (outputHandler && !outputHandler->replayBuffer)
|
if (outputHandler && !outputHandler->replayBuffer)
|
||||||
sysTrayReplayBuffer->setEnabled(false);
|
sysTrayReplayBuffer->setEnabled(false);
|
||||||
|
|
||||||
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
connect(trayIcon.data(),
|
||||||
|
SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
||||||
this,
|
this,
|
||||||
SLOT(IconActivated(QSystemTrayIcon::ActivationReason)));
|
SLOT(IconActivated(QSystemTrayIcon::ActivationReason)));
|
||||||
connect(showHide, SIGNAL(triggered()),
|
connect(showHide, SIGNAL(triggered()),
|
||||||
|
|
|
@ -138,9 +138,9 @@ private:
|
||||||
const char *copyFiltersString;
|
const char *copyFiltersString;
|
||||||
bool copyVisible = true;
|
bool copyVisible = true;
|
||||||
|
|
||||||
QPointer<QThread> updateCheckThread;
|
QScopedPointer<QThread> updateCheckThread;
|
||||||
QPointer<QThread> introCheckThread;
|
QScopedPointer<QThread> introCheckThread;
|
||||||
QPointer<QThread> logUploadThread;
|
QScopedPointer<QThread> logUploadThread;
|
||||||
|
|
||||||
QPointer<OBSBasicInteraction> interaction;
|
QPointer<OBSBasicInteraction> interaction;
|
||||||
QPointer<OBSBasicProperties> properties;
|
QPointer<OBSBasicProperties> properties;
|
||||||
|
@ -184,7 +184,7 @@ private:
|
||||||
|
|
||||||
QPointer<QPushButton> replayBufferButton;
|
QPointer<QPushButton> replayBufferButton;
|
||||||
|
|
||||||
QPointer<QSystemTrayIcon> trayIcon;
|
QScopedPointer<QSystemTrayIcon> trayIcon;
|
||||||
QPointer<QAction> sysTrayStream;
|
QPointer<QAction> sysTrayStream;
|
||||||
QPointer<QAction> sysTrayRecord;
|
QPointer<QAction> sysTrayRecord;
|
||||||
QPointer<QAction> sysTrayReplayBuffer;
|
QPointer<QAction> sysTrayReplayBuffer;
|
||||||
|
|
Loading…
Reference in New Issue