diff --git a/pgadmin/frm/events.cpp b/pgadmin/frm/events.cpp index 7cc49d7..eb453f8 100644 --- a/pgadmin/frm/events.cpp +++ b/pgadmin/frm/events.cpp @@ -39,6 +39,10 @@ #include "schema/edbPrivateSynonym.h" #include "dlg/dlgProperty.h" +// Mutex to protect the "currentObject" from race condition. +// +static wxMutex s_CellChangeMutex; + // Event table BEGIN_EVENT_TABLE(frmMain, pgFrame) EVT_CHILD_FOCUS( frmMain::OnChildFocus) @@ -411,7 +415,12 @@ void frmMain::execSelChange(wxTreeItemId item, bool currentNode) // Get the item data, and feed it to the relevant handler, // cast as required. - currentObject = browser->GetObject(item); + // + // Locking the section, to prevent the race condition among, "onSelRightClick" and "execSelChange". + // + s_CellChangeMutex.Lock(); + currentObject = browser->GetObject(item); + s_CellChangeMutex.Unlock(); // If we didn't get an object, then we may have a right click, or // invalid click, so ignore. @@ -729,11 +738,16 @@ void frmMain::OnSelRightClick(wxTreeEvent &event) if (item != browser->GetSelection()) { browser->SelectItem(item); + // Preventing to change "currentObject" by "execSelchange" function by another thread. + // Will hold the lock, until we do popup on the respective object. + // + s_CellChangeMutex.Lock(); currentObject = browser->GetObject(item); } if (currentObject) doPopup(browser, event.GetPoint(), currentObject); + s_CellChangeMutex.Unlock(); }