瀏覽代碼

UI: Fix QLabel leak in OBSPropertiesView::AddProperty

OBS_PROPERTY_GROUP creates neither a widget nor a label, causing
AddProperty to create a default one. Without a widget, it does not
get attached to the layout, resulting in a memory leak.

This commit also simplifies a bit of the code to avoid repeatedly
testing the same condition.
Richard Stanway 3 年之前
父節點
當前提交
40a598008d
共有 1 個文件被更改,包括 15 次插入10 次删除
  1. 15 10
      UI/properties-view.cpp

+ 15 - 10
UI/properties-view.cpp

@@ -1452,27 +1452,32 @@ void OBSPropertiesView::AddProperty(obs_property_t *property,
 		AddColorAlpha(property, layout, label);
 	}
 
-	if (widget && !obs_property_enabled(property))
-		widget->setEnabled(false);
+	if (!widget && !label)
+		return;
 
 	if (!label && type != OBS_PROPERTY_BOOL &&
 	    type != OBS_PROPERTY_BUTTON && type != OBS_PROPERTY_GROUP)
 		label = new QLabel(QT_UTF8(obs_property_description(property)));
 
-	if (warning && label) //TODO: select color based on background color
-		label->setStyleSheet("QLabel { color: red; }");
+	if (label) {
+		if (warning) //TODO: select color based on background color
+			label->setStyleSheet("QLabel { color: red; }");
 
-	if (label && minSize) {
-		label->setMinimumWidth(minSize);
-		label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
-	}
+		if (minSize) {
+			label->setMinimumWidth(minSize);
+			label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
+		}
 
-	if (label && !obs_property_enabled(property))
-		label->setEnabled(false);
+		if (!obs_property_enabled(property))
+			label->setEnabled(false);
+	}
 
 	if (!widget)
 		return;
 
+	if (!obs_property_enabled(property))
+		widget->setEnabled(false);
+
 	if (obs_property_long_description(property)) {
 		bool lightTheme = palette().text().color().redF() < 0.5;
 		QString file = lightTheme ? ":/res/images/help.svg"