Browse Source

Reset data_source to NULL upon detaching

Prevents pointer dereference to possibly freed data source in the destructor
Victor Luchits 11 years ago
parent
commit
8a32c8f97d
1 changed files with 6 additions and 2 deletions
  1. 6 2
      Source/Controls/ElementFormControlDataSelect.cpp

+ 6 - 2
Source/Controls/ElementFormControlDataSelect.cpp

@@ -43,8 +43,10 @@ ElementFormControlDataSelect::ElementFormControlDataSelect(const Rocket::Core::S
 
 ElementFormControlDataSelect::~ElementFormControlDataSelect()
 {
-	if (data_source != NULL)
+	if (data_source != NULL) {
 		data_source->DetachListener(this);
+		data_source = NULL;
+	}
 }
 
 // Sets the data source the control's options are driven from.
@@ -76,8 +78,10 @@ void ElementFormControlDataSelect::OnAttributeChange(const Core::AttributeNameLi
 
 	if (changed_attributes.find("source") != changed_attributes.end())
 	{
-		if (data_source != NULL)
+		if (data_source != NULL) {
 			data_source->DetachListener(this);
+			data_source = NULL;
+		}
 
 		initialised = false;
 	}