Errata

 

Home Purchase Preface Contents Examples Resources Errata Site Guide

 COM and CORBAŽ Side by Side


Errata

Errors always pop up where you least expect them. This page describes errors contained in the book.
  

Page 78 - Attempting to call SysFreeString() with an unset pointer.

Thanks to Tomas Palmer for pointing this out. Here is a code snippet identifying the problem.
BOOL MyCheckingAccount::Init(const CString& name,
                             const CString& serverName,
                             CString& errmsg)
{
    Reset();

    // Create server info.
    COSERVERINFO  serverInfo;
    COSERVERINFO* pServerInfo;
    if ( serverName.IsEmpty() )
    {
        // Use local server.
        pServerInfo = NULL;
    }
    else
    {
        serverInfo.dwReserved1 = 0;
        serverInfo.dwReserved2 = 0;
        serverInfo.pwszName    = serverName.AllocSysString();
        serverInfo.pAuthInfo   = NULL;
        pServerInfo = &serverInfo;
    }

    // Create MULTI_QI array to get all pertinent interfaces.
    MULTI_QI mqi[] =
    {
        {&IID_IAccount,         NULL, 0},
        {&IID_IAccountInit,     NULL, 0},
        {&IID_ICheckingAccount, NULL, 0},
    };

    // Create a server object instance.
    HRESULT hr;
    hr = CoCreateInstanceEx
            (CLSID_Ch3CheckingAccount, NULL,
             CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER,
             pServerInfo, 3, mqi);

    ::SysFreeString(serverInfo.pwszName);   // ****** ERROR ******
Notice that if the serverName argument to Init() is an empty string, serverInfo.pwszName never gets set. To correct the problem, a check needs to be made before calling ::SysFreeString(). For example, the check could be written as shown here:
    if ( !serverName.IsEmpty() )
    {
        ::SysFreeString(serverInfo.pwszName);
    }

 

Home ] Purchase ] Preface ] Contents ] Examples ] Resources ] [ Errata ] Site Guide ]

Send mail to jpritchard@pobox.com with questions or comments about this web site.
Last modified: August 12, 2003