title: Application crash at stl string creation
body: <p>I am getting an application crash in two locations of my application. One of the locations is the following statement of the method given below. The application crashes while creating an stl string object for the string pass to LogMessage method.</p>
  
  <pre><code>EMCoreLogger::GetLoggerInstance()-&gt;LogMessage("Sending message completed successfully",
                              "CGEMCustomMessageService",Information);
  </code></pre>
  
  <p>The callstack is given below </p>
  
  <pre><code>    msvcr90.dll!_crt_debugger_hook(int _Reserved=101180712)  Line 65    C
      msvcr90.dll!_invalid_parameter(const wchar_t * pszExpression=0x00000000, const wchar_t * pszFunction=0x00000000, const wchar_t * pszFile=0x00000000, unsigned int nLine=0, unsigned int pReserved=0)  Line 112 + 0x7 bytes  C++
      msvcr90.dll!memcpy_s(void * dst=0x0607e5d8, unsigned int sizeInBytes=0, const void * src=0x084beac8, unsigned int count=38)  Line 55 + 0x19 bytes   C
      msvcp90.dll!std::char_traits&lt;char&gt;::_Copy_s(char * _First1=0x0607e5d8, unsigned int _Size_in_bytes=0, const char * _First2=0x084beac8, unsigned int _Count=38)  Line 583    C++
      msvcp90.dll!std::_Traits_helper::copy_s&lt;std::char_traits&lt;char&gt; &gt;(char * _First1=0x0607e5d8, unsigned int _Size=0, const char * _First2=0x084beac8, unsigned int _Count=38, std::_Secure_char_traits_tag __formal={...})  Line 714 + 0x11 bytes  C++
      msvcp90.dll!std::_Traits_helper::copy_s&lt;std::char_traits&lt;char&gt; &gt;(char * _First1=0x0607e5d8, unsigned int _Size=0, const char * _First2=0x084beac8, unsigned int _Count=38)  Line 706 + 0x14 bytes   C++
      msvcp90.dll!std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt;::assign(const char * _Ptr=0x084beac8, unsigned int _Count=38)  Line 1086 + 0x1b bytes  C++
      msvcp90.dll!std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt;::assign(const char * _Ptr=0x084beac8)  Line 1095 + 0x16 bytes  C++
      msvcp90.dll!std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt;::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt;(const char * _Ptr=0x084beac8)  Line 664   C++
  &gt;   GemCore.dll!CGEMCustomMessageService::SendProcessMessage(unsigned short tkt=167, SSECSMSG * mb=0x0607eafc, int nFuncID=4, int * pnClientIds=0x1bf5aff8, int nClientCount=1)  Line 566 + 0x34 bytes  C++
      GemCore.dll!CCustomMessageRouter::PA_ProcessPrimaryMessage(unsigned short tkt=167, SSECSMSG * mb=0x0607eafc, int nFuncID=4, int * pnClientIds=0x1bf5aff8, int nClientCount=1)  Line 54 + 0x1d bytes C++
      PAL.dll!CPALProtocolPlugin::PA_ProcessPrimaryMessage(unsigned short tkt=167, SSECSMSG * mb=0x0607eafc, int nFuncID=4, int * pnClientIds=0x1bf5aff8, int nClientCount=1)  Line 50 + 0x2c bytes   C++
      CustomSECSII_R.dll!CCustomMessageTransportPlugin::ProcessPrmryMsg(char * pBuffer=0x4794cfe0, unsigned long dwBufSize=31, bool bRepExpected=true, unsigned char byStream='', unsigned char byFunction='', unsigned short tkt=167, int nFuncID=4, int * pnClientIds=0x1bf5aff8, int nClientCount=1)  Line 85 + 0x20 bytes C++
      TAL.dll!CMessageHandler::HandleCustomMessage(char * pBuffer=0x4794cfe0, unsigned long dwBufSize=31, bool bRepExpected=true, unsigned long dwTransID=2839, unsigned long dwTransTwoID=0, unsigned char byStream='', unsigned char byFunction='', unsigned char * pHeader=0x478f8ff0, unsigned char byPType=0, int nScanFuncId=-1, int nProcessFuncId=4, std::vector&lt;int,std::allocator&lt;int&gt; &gt; pVecClientId=[1](1))  Line 2949 + 0x4b bytes   C++
      TAL.dll!CMessageHandler::ReceiveMessage(char * pBuffer=0x4794cfe0, unsigned long dwBufSize=31, bool bRepExpected=true, unsigned long dwTransID=2839, unsigned long dwTransTwoID=0, unsigned char byStream='', unsigned char byFunction='', unsigned char * pHeader=0x478f8ff0, unsigned char byPType=0)  Line 1220 + 0x6c bytes C++
      TAL.dll!CTALTransportObject::ReceiveMessage(char * szBuffer=0x4794cfe0, unsigned long dwBufSize=31, bool bRepExpected=true, unsigned long dwSECS1TRID=2839, unsigned long dwSECS2TRID=0, unsigned char byStream='', unsigned char byFunction='', unsigned char * pbyHeader=0x478f8ff0, unsigned char byPType=0)  Line 199 + 0x30 bytes  C++
      HSMS.dll!CDataMessageMngr::RespondToMessage(CMessage * pMessage=0x0607ff28)  Line 392   C++
      HSMS.dll!CLowerRouter::RecieveData()  Line 820  C++
      HSMS.dll!CLowerRouter::RecievingThread(void * pVoid=0x036f9fa0)  Line 566   C++
      kernel32.dll!7c80b729()     
      [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
  </code></pre>
  
  <p>I enabled <strong>pageheap</strong> to detect heap corruption. I also enabled <strong>Run-Time Error Checks /RTCs</strong> to detect stack corruption. I am not able to detect the root cause.</p>
  
  <p><em><strong>How can I proceed to get the cause of the issue?</em></strong></p>
  
  <pre><code>bool
  CGEMCustomMessageService::SendProcessMessage(SECSTICKET tkt, PSECSMSG mb,int nFuncID, int* pnClientIds,int nClientCount)
  {
      bool bRetCode = true;
      int nRetCode = 0;
      char chLog[1024] = {0};
      CEALCustomMessagePlugin *pCustomMessagePlugin = CEALCustomMessagePlugin::Instance();
      int nStream   = mb-&gt;nStream;
      int nFunction = mb-&gt;nFunction;
      int nTicket   = tkt;
  
          CGEMEqpmntService* pGEMEqpmntService = (CGEMEqpmntService *)CGEMEqpmntService::Instance();
          EQP_CTRL_STATE eControlState = STATE_HOSTOFFLINE;
          sprintf(chLog,"Sending S%d,F%d with ticket[%d]",mb-&gt;nStream, mb-&gt;nFunction,tkt);
          LogDataMessage(chLog,"CGEMCustomMessageService",Information);
  
          if (NULL != pCustomMessagePlugin)
          {  
  
                      GEMCoreLogger::GetLoggerInstance()-&gt;LogMessage("Control state is Online remote sending message to client",
                          "CGEMCustomMessageService",Debug);
                      nRetCode = pCustomMessagePlugin-&gt;GEMT_ProcessPrimaryMessage(tkt,mb,nFuncID,pnClientIds,nClientCount);
  
                      GEMCoreLogger::GetLoggerInstance()-&gt;LogMessage("Sending message completed successfully",
                          "CGEMCustomMessageService",Information);
          }
  
      return bRetCode;
  }
  </code></pre>