$OpenBSD: patch-pgadmin_frm_events_cpp,v 1.2 2015/09/02 10:03:34 landry Exp $
--- pgadmin/frm/events.cpp.orig	Fri May 30 12:42:41 2014
+++ pgadmin/frm/events.cpp	Mon Aug 24 17:37:18 2015
@@ -41,7 +41,7 @@
 
 // Mutex to protect the "currentObject" from race conditions.
 //
-static wxMutex s_currentObjectMutex;
+static wxMutex *currentObjectMutex = new wxMutex( wxMUTEX_RECURSIVE );
 
 // Event table
 BEGIN_EVENT_TABLE(frmMain, pgFrame)
@@ -418,9 +418,9 @@ void frmMain::execSelChange(wxTreeItemId item, bool cu
 	//
 	// Lock the assignment to prevent the race conditions between onSelRightClick and execSelChange.
 	//
-	s_currentObjectMutex.Lock();
+	currentObjectMutex->Lock();
 	currentObject = browser->GetObject(item);
-	s_currentObjectMutex.Unlock();
+	currentObjectMutex->Unlock();
 
 	// If we didn't get an object, then we may have a right click, or
 	// invalid click, so ignore.
@@ -735,6 +735,7 @@ void frmMain::OnContextMenu(wxCommandEvent &event)
 void frmMain::OnSelRightClick(wxTreeEvent &event)
 {
 	wxTreeItemId item = event.GetItem();
+
 	if (item != browser->GetSelection())
 	{
 		browser->SelectItem(item);
@@ -742,13 +743,16 @@ void frmMain::OnSelRightClick(wxTreeEvent &event)
 		// Prevent changes to "currentObject" by "execSelchange" function by another thread.
 		// Will hold the lock until we do popup on the respective object.
 		//
-		s_currentObjectMutex.Lock();
+		currentObjectMutex->Lock();
 		currentObject = browser->GetObject(item);
 	}
+	else
+		currentObjectMutex->Lock();
 
 	if (currentObject)
 		doPopup(browser, event.GetPoint(), currentObject);
-	s_currentObjectMutex.Unlock();
+
+	currentObjectMutex->Unlock();
 }
 
 
