[commit] r2718 - in trunk: Doc GME/Mga

GMESRC Repository Notifications gme-commit at list.isis.vanderbilt.edu
Wed Dec 6 13:41:20 CST 2017


Author: ksmyth
Date: Wed Dec  6 13:41:19 2017
New Revision: 2718

Log:
Fix crash when CMgaAddOn::Destroy is called before CMgaAddon::~CMgaAddon. (active flag was not set correctly)

Modified:
   trunk/Doc/README_in.txt
   trunk/GME/Mga/MgaProject.cpp
   trunk/GME/Mga/MgaTerritory.cpp
   trunk/GME/Mga/MgaTerritory.h

Modified: trunk/Doc/README_in.txt
==============================================================================
--- trunk/Doc/README_in.txt	Wed Nov 15 15:30:22 2017	(r2717)
+++ trunk/Doc/README_in.txt	Wed Dec  6 13:41:19 2017	(r2718)
@@ -25,6 +25,11 @@
 1. Release Notes
 ************************************************
 
+Release Notes
+----------------------------------
+  - Binary compatibility with 11.12.2
+  - Fix rare crash when IMgaAddOn is garbage collected (e.g. C# AddOns)
+
 Release Notes of Release 17.11.14
 ----------------------------------
   - Binary compatibility with 11.12.2

Modified: trunk/GME/Mga/MgaProject.cpp
==============================================================================
--- trunk/GME/Mga/MgaProject.cpp	Wed Nov 15 15:30:22 2017	(r2717)
+++ trunk/GME/Mga/MgaProject.cpp	Wed Dec  6 13:41:19 2017	(r2718)
@@ -1163,6 +1163,7 @@
 		CComPtr< CMgaAddOn > saddon;
 		CreateComObject(saddon);
 		saddon->mgaproject = this;
+		saddon->mgaproject->AddRef();
 		saddon->progid = autoaddoncreate_progid;
 		alladdons.push_front(saddon);
 		saddon->handler=sink;

Modified: trunk/GME/Mga/MgaTerritory.cpp
==============================================================================
--- trunk/GME/Mga/MgaTerritory.cpp	Wed Nov 15 15:30:22 2017	(r2717)
+++ trunk/GME/Mga/MgaTerritory.cpp	Wed Dec  6 13:41:19 2017	(r2718)
@@ -131,14 +131,19 @@
 }
 
 STDMETHODIMP CMgaAddOn::CheckProject(IMgaProject *project) {
-	return(project == mgaproject? S_OK : E_MGA_FOREIGN_PROJECT);
+	COMTRY {
+		if (!IsEqualObject(project, (IMgaProject*)mgaproject)) {
+			COMTHROW(E_MGA_FOREIGN_PROJECT);
+		}
+	} COMCATCH(;)
 }
 
 
 STDMETHODIMP CMgaAddOn::Destroy() {
 	COMTRY {
 		MARKSIG('8'); 
-		if(!handler) COMTHROW(E_MGA_TARGET_DESTROYED);
+		if (!handler)
+			COMTHROW(E_MGA_TARGET_DESTROYED);
 		CMgaProject::addoncoll::iterator i = mgaproject->alladdons.begin(), end = mgaproject->alladdons.end();
 		while (i != end) {
 			if (*i == this) {
@@ -154,7 +159,6 @@
 			
 		}
 		ASSERT(("addon not found among project addons",false));	
-		active = false;
 	} COMCATCH(;)
 }
 

Modified: trunk/GME/Mga/MgaTerritory.h
==============================================================================
--- trunk/GME/Mga/MgaTerritory.h	Wed Nov 15 15:30:22 2017	(r2717)
+++ trunk/GME/Mga/MgaTerritory.h	Wed Dec  6 13:41:19 2017	(r2718)
@@ -95,7 +95,6 @@
 	public IDispatchImpl<IMgaAddOn, &__uuidof(IMgaAddOn), &__uuidof(__MGALib)>
 {
     DEFSIG;
-	bool active;
 	bool automatic;   // this addon was created automatically
 public:
 	CMgaAddOn()	{
@@ -103,7 +102,6 @@
 #ifdef DEBUG
 		MGA_TRACE("Constructed: %s - %08X\n", sig, this);
 #endif
-		active = true;
 		notified = false;
 		automatic = false;
 	}
@@ -112,7 +110,9 @@
 		MGA_TRACE("Destructed: %s - %08X\n", sig, this);
 #endif
 		MARKSIG('9'); 
-		if(active) Destroy();	
+		if (handler)
+			Destroy();
+		mgaproject->Release();
 	}
 
 	void SetAutomatic() { automatic = true; }
@@ -131,15 +131,18 @@
 	STDMETHOD(put_Priority)( long newVal);
 	STDMETHOD(put_EventMask)( unsigned long mask) { 
 		COMTRY {
-			if(!handler) COMTHROW( E_MGA_TARGET_DESTROYED);
+			if (!handler)
+				COMTHROW(E_MGA_TARGET_DESTROYED);
 			eventmask = mask;
 		} COMCATCH(;);
 	};
 	STDMETHOD(get_Project)(IMgaProject **pVal) { 
 		COMTRY {
-			if(!handler) COMTHROW( E_MGA_TARGET_DESTROYED);
+			if (!handler)
+				COMTHROW(E_MGA_TARGET_DESTROYED);
 			CHECK_OUTPTRPAR(pVal); 
-			*pVal = mgaproject; (*pVal)->AddRef(); 
+			*pVal = mgaproject;
+			(*pVal)->AddRef(); 
 		} COMCATCH(;);
 	};
 	STDMETHOD(CheckProject)( IMgaProject *project);  
@@ -147,7 +150,7 @@
 
 	unsigned long eventmask;
 	bool notified;
-	CMgaProject *mgaproject;
+	CMgaProject* mgaproject;
 	_bstr_t progid;
 	CComPtr<IMgaEventSink> handler;    // non-null if object active 
 };


More information about the gme-commit mailing list