UI: Fix potential memory leak in properties

When hitting the Cancel button, cleanup code needs to go through the
reject() callback as well.
This commit is contained in:
kc5nra 2015-03-22 15:24:01 -07:00 committed by jp9000
parent 87965fa9eb
commit dac3fd88e0
2 changed files with 32 additions and 12 deletions

View File

@ -55,6 +55,9 @@ OBSBasicProperties::OBSBasicProperties(QWidget *parent, OBSSource source_)
if (cx > 400 && cy > 400)
resize(cx, cy);
/* The OBSData constructor increments the reference once */
obs_data_release(oldSettings);
OBSData settings = obs_source_get_settings(source);
obs_data_apply(oldSettings, settings);
obs_data_release(settings);
@ -193,6 +196,32 @@ void OBSBasicProperties::timerEvent(QTimerEvent *event)
}
}
void OBSBasicProperties::Cleanup()
{
// remove draw callback and release display in case our drawable
// surfaces go away before the destructor gets called
obs_display_remove_draw_callback(display,
OBSBasicProperties::DrawPreview, this);
display = nullptr;
config_set_int(App()->GlobalConfig(), "PropertiesWindow", "cx",
width());
config_set_int(App()->GlobalConfig(), "PropertiesWindow", "cy",
height());
}
void OBSBasicProperties::reject()
{
if (!acceptClicked && (CheckSettings() != 0)) {
if (!ConfirmQuit()) {
return;
}
}
Cleanup();
done(0);
}
void OBSBasicProperties::closeEvent(QCloseEvent *event)
{
if (!acceptClicked && (CheckSettings() != 0)) {
@ -206,18 +235,7 @@ void OBSBasicProperties::closeEvent(QCloseEvent *event)
if (!event->isAccepted())
return;
obs_data_release(oldSettings);
// remove draw callback and release display in case our drawable
// surfaces go away before the destructor gets called
obs_display_remove_draw_callback(display,
OBSBasicProperties::DrawPreview, this);
display = nullptr;
config_set_int(App()->GlobalConfig(), "PropertiesWindow", "cx",
width());
config_set_int(App()->GlobalConfig(), "PropertiesWindow", "cy",
height());
Cleanup();
}
void OBSBasicProperties::Init()

View File

@ -50,6 +50,7 @@ private:
static void DrawPreview(void *data, uint32_t cx, uint32_t cy);
bool ConfirmQuit();
int CheckSettings();
void Cleanup();
private slots:
void OnPropertiesResized();
@ -65,4 +66,5 @@ protected:
virtual void resizeEvent(QResizeEvent *event) override;
virtual void timerEvent(QTimerEvent *event) override;
virtual void closeEvent(QCloseEvent *event) override;
virtual void reject() override;
};