I'm attempting to copy a string out of a arbitrary position in a buffer. I can copy out the string but I'm left with a memory leak that I do not know how to solve. Is there a better way to do this; if not, how do I solve the memory leak.
if(_usCurrentPosition + 1 >= m_usBufferLength) // check the char
goto ErrorOccurred;
unsigned char _ucLength = m_pcBufferData[_usCurrentPosition];
++_usCurrentPosition;
if(_usCurrentPosition + _ucLength > m_usBufferLength) // check the string
goto ErrorOccurred;
string* str = va_arg(vl, string*);
char* _cTemp;
_cTemp = new char[_ucLength]; //TODO: MEMORY LEAK no delete of array
memcpy(_cTemp, &m_pcBufferData[_usCurrentPosition], _ucLength);
(*str).assign(_cTemp, _ucLength);
//delete[] _cTemp; //causes error
_usCurrentPosition += _ucLength;