[mapguide-internals] Blocking issue in Mapguide 2.4

Walt Welton-Lair walt.welton-lair at autodesk.com
Mon Feb 18 12:47:47 PST 2013


Hi Bruno,

I'm not convinced your suggested code fix is right.

Starting at the top of MgOpUpdateFeatures::Execute().  There's MG_FEATURE_SERVICE_TRY() which has the definition:

    Ptr<MgException> mgException;
    STRING mgStackParams;
    try
    {

Notice that mgException is a smart-pointer, and a variable on the stack.

Then there's MG_FEATURE_SERVICE_CATCH(L"MgOpUpdateFeatures.Execute"), whose definition includes:

    }
    catch (MgException* e)
    {
        mgException = e;
        mgException->AddStackTraceInfo(methodName, mgStackParams, __LINE__, __WFILE__);
    }

So in the case of an MgException, the mgException takes ownership of the exception object.  Note that there's no addref needed here - the MgException object's ref-count should have already been properly set by the code that threw the exception.  (I would expect its ref-count to be 1.  If it's greater than 1 then that's suspicious and the code which threw the exception should be checked.)

Then at the end there's MG_FEATURE_SERVICE_THROW(), whose definition is:

    if (mgException != NULL)
    {
        (*mgException).AddRef();
        mgException->Raise();
    }

The MgException object must be addref'ed to balance the ref-count decrease which happens when the mgException smart-pointer gets destroyed.  If we don't addref it the MgException object is deleted when the smart-pointer is deleted (assuming it's ref-count was originally 1), and any subsequent catch block for the MgException will end up with a pointer to a deleted object.

I suggest debugging this again, and monitoring the ref-count of the MgException object in the debugger as it makes its way through the different try / catch / throw blocks.

Walt


-----Original Message-----
From: mapguide-internals-bounces at lists.osgeo.org [mailto:mapguide-internals-bounces at lists.osgeo.org] On Behalf Of Bruno Scott
Sent: Monday, February 18, 2013 9:58 AM
To: mapguide-internals at lists.osgeo.org
Subject: Re: [mapguide-internals] Blocking issue in Mapguide 2.4

I have found something

At the end of MgOpUpdateFeatures::Execute
if we replace
*/  MG_FEATURE_SERVICE_THROW()/*
by
/*    if (mgException != NULL) 
    { 
        mgException->Raise();
    }*/

It fixes the problem.

normally MG_FEATURE_SERVICE_THROW is defined this way
    if (mgException != NULL) 
    { 
        (*mgException).AddRef();
        mgException->Raise();
    }

It seems that in this case we do not have to addRef the exception.
The Exception would not been destroyed and further call to the service
failed with wrong message

I'm not pretty sure that the way to fix the problem


Bruno



--
View this message in context: http://osgeo-org.1560.n6.nabble.com/Blocking-issue-in-Mapguide-2-4-tp5034831p5034922.html
Sent from the MapGuide Internals mailing list archive at Nabble.com.
_______________________________________________
mapguide-internals mailing list
mapguide-internals at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-internals


More information about the mapguide-internals mailing list