Wondering if anyone could give this a once over to make sure I'm preventing memory leaks, this function gets called ALOT and not
really thrilled if it starts leaking.
Code:
/* Function WriteToLog(), Sets A New String To The Log Message Pointer & Writes To Log File */
void WriteToLog(TCHAR* pMessage)
{
/* Check To Make Sure We Have A New String */
if(!pMessage)
{
return;
}
/* Reset The Old Pointer Just To Be Sure */
if (g_pLogMsg)
{
delete[] g_pLogMsg;
g_pLogMsg = NULL;
}
/* Assign The New String To The Pointer */
g_pLogMsg = new TCHAR[lstrlen(pMessage) + 1];
lstrcpy(g_pLogMsg, pMessage);
/* Write To Log File */
WriteFile(g_hLogFile, g_pLogMsg, lstrlen(g_pLogMsg), &g_dwStored, NULL);
/* Reset The Old Pointer Again */
if (g_pLogMsg)
{
delete[] g_pLogMsg;
g_pLogMsg = NULL;
}
return;
}