[REGEXPL]

Fix memory leaks
Fix broken if condition
Use delete[] operator for allocations made with new[] operator
Properly check for failed allocations by not throwing exception

svn path=/trunk/; revision=54034
This commit is contained in:
Pierre Schweitzer 2011-10-06 21:36:10 +00:00
parent 7e02fbd0dd
commit c91f9ef382
16 changed files with 100 additions and 82 deletions

View file

@ -49,9 +49,9 @@ public:
size_t s = _tcslen(pszText); size_t s = _tcslen(pszText);
if (m_pszText) if (m_pszText)
delete m_pszText; delete[] m_pszText;
m_pszText = new TCHAR [s+(b?3:1)]; // if we have spaces in unique part, we need 2 addtional chars for " m_pszText = new (std::nothrow) TCHAR [s+(b?3:1)]; // if we have spaces in unique part, we need 2 addtional chars for "
if (!m_pszText) if (!m_pszText)
return FALSE; return FALSE;
@ -75,7 +75,7 @@ public:
~CCompletionMatch() ~CCompletionMatch()
{ {
if (m_pszText) if (m_pszText)
delete m_pszText; delete[] m_pszText;
} }
private: private:
@ -129,20 +129,20 @@ CCompletionList::~CCompletionList()
DeleteList(); DeleteList();
if (m_pszContext) if (m_pszContext)
delete m_pszContext; delete[] m_pszContext;
if (m_pszBegin) if (m_pszBegin)
delete m_pszBegin; delete[] m_pszBegin;
if (m_pszCurrentKey) if (m_pszCurrentKey)
delete m_pszCurrentKey; delete[] m_pszCurrentKey;
} }
void CCompletionList::Invalidate() void CCompletionList::Invalidate()
{ {
if (m_pszCurrentKey) if (m_pszCurrentKey)
{ {
delete m_pszCurrentKey; delete[] m_pszCurrentKey;
m_pszCurrentKey = NULL; m_pszCurrentKey = NULL;
} }
} }
@ -161,38 +161,48 @@ BOOL CCompletionList::IsNewCompletion(const TCHAR *pszContext, const TCHAR *pszB
rblnNew = TRUE; rblnNew = TRUE;
if (m_pszContext) if (m_pszContext)
{ {
delete m_pszContext; delete[] m_pszContext;
m_pszContext = NULL; m_pszContext = NULL;
} }
if (m_pszBegin) if (m_pszBegin)
{ {
delete m_pszBegin; delete[] m_pszBegin;
m_pszBegin = NULL; m_pszBegin = NULL;
} }
if (m_pszCurrentKey) if (m_pszCurrentKey)
{ {
delete m_pszCurrentKey; delete[] m_pszCurrentKey;
m_pszCurrentKey = NULL; m_pszCurrentKey = NULL;
} }
size_t s = _tcslen(pszContext); size_t s = _tcslen(pszContext);
m_pszContext = new TCHAR[s+1]; m_pszContext = new (std::nothrow) TCHAR[s+1];
if (!m_pszContext) if (!m_pszContext)
return FALSE; return FALSE;
_tcscpy(m_pszContext,pszContext); _tcscpy(m_pszContext,pszContext);
s = _tcslen(pszBegin); s = _tcslen(pszBegin);
m_pszBegin = new TCHAR[s+1]; m_pszBegin = new (std::nothrow) TCHAR[s+1];
if (!m_pszBegin) if (!m_pszBegin)
{
delete[] m_pszContext;
m_pszContext = NULL;
return FALSE; return FALSE;
}
_tcscpy(m_pszBegin,pszBegin); _tcscpy(m_pszBegin,pszBegin);
s = _tcslen(pszCurrentKey); s = _tcslen(pszCurrentKey);
m_pszCurrentKey = new TCHAR[s+1]; m_pszCurrentKey = new (std::nothrow) TCHAR[s+1];
if (!m_pszCurrentKey) if (!m_pszCurrentKey)
{
delete[] m_pszContext;
delete[] m_pszBegin;
m_pszContext = NULL;
m_pszBegin = NULL;
return FALSE; return FALSE;
}
_tcscpy(m_pszCurrentKey,pszCurrentKey); _tcscpy(m_pszCurrentKey,pszCurrentKey);
return TRUE; return TRUE;
@ -206,7 +216,7 @@ BOOL CCompletionList::Add(const TCHAR *pszText, BOOL blnIsKey)
{ {
if (_tcsnicmp(pszText,m_pszBegin,_tcslen(m_pszBegin)) != 0) if (_tcsnicmp(pszText,m_pszBegin,_tcslen(m_pszBegin)) != 0)
return TRUE; return TRUE;
CCompletionMatch *pNode = new CCompletionMatch; CCompletionMatch *pNode = new (std::nothrow) CCompletionMatch;
if (!pNode) if (!pNode)
return FALSE; return FALSE;
if (!pNode->Init(pszText)) if (!pNode->Init(pszText))
@ -363,7 +373,7 @@ BOOL FillCompletion(const TCHAR *pszKey)
if (nError != ERROR_SUCCESS) if (nError != ERROR_SUCCESS)
return FALSE; return FALSE;
pszSubkeyName = new TCHAR[nKeyNameSize+dwMaxSubkeyNameLength+1]; pszSubkeyName = new (std::nothrow) TCHAR[nKeyNameSize+dwMaxSubkeyNameLength+1];
if (!pszSubkeyName) if (!pszSubkeyName)
goto Abort; goto Abort;
@ -393,7 +403,7 @@ BOOL FillCompletion(const TCHAR *pszKey)
goto Abort; goto Abort;
} }
pszValueName = new TCHAR[nKeyNameSize+dwMaxValueNameSize+1]; pszValueName = new (std::nothrow) TCHAR[nKeyNameSize+dwMaxValueNameSize+1];
if (!pszValueName) if (!pszValueName)
goto Abort; goto Abort;
@ -415,15 +425,15 @@ BOOL FillCompletion(const TCHAR *pszKey)
} }
if (pszValueName) if (pszValueName)
delete pszValueName; delete[] pszValueName;
if (pszSubkeyName) if (pszSubkeyName)
delete pszSubkeyName; delete[] pszSubkeyName;
return TRUE; return TRUE;
Abort: Abort:
if (pszValueName) if (pszValueName)
delete pszValueName; delete[] pszValueName;
if (pszSubkeyName) if (pszSubkeyName)
delete pszSubkeyName; delete[] pszSubkeyName;
return FALSE; return FALSE;
} }

View file

@ -71,11 +71,11 @@ CConsole::CConsole()
CConsole::~CConsole() CConsole::~CConsole()
{ {
if (m_pchBuffer) if (m_pchBuffer)
delete m_pchBuffer; delete[] m_pchBuffer;
if (m_pchBuffer1) if (m_pchBuffer1)
delete m_pchBuffer1; delete[] m_pchBuffer1;
if (m_pchBuffer2) if (m_pchBuffer2)
delete m_pchBuffer2; delete[] m_pchBuffer2;
if (m_blnOldInputModeSaved) if (m_blnOldInputModeSaved)
SetConsoleMode(m_hStdIn,m_dwOldInputMode); SetConsoleMode(m_hStdIn,m_dwOldInputMode);
@ -946,15 +946,15 @@ TCHAR * CConsole::Init(DWORD dwBufferSize, DWORD dwMaxHistoryLines)
if (m_pchBuffer2) delete m_pchBuffer2; if (m_pchBuffer2) delete m_pchBuffer2;
m_pchBuffer2 = NULL; m_pchBuffer2 = NULL;
m_pchBuffer = new TCHAR [dwBufferSize]; m_pchBuffer = new (std::nothrow) TCHAR [dwBufferSize];
if (!m_pchBuffer) goto Abort; if (!m_pchBuffer) goto Abort;
m_pchBuffer[dwBufferSize-1] = 0; m_pchBuffer[dwBufferSize-1] = 0;
m_pchBuffer1 = new TCHAR [dwBufferSize]; m_pchBuffer1 = new (std::nothrow) TCHAR [dwBufferSize];
if (!m_pchBuffer1) goto Abort; if (!m_pchBuffer1) goto Abort;
m_pchBuffer1[dwBufferSize-1] = 0; m_pchBuffer1[dwBufferSize-1] = 0;
m_pchBuffer2 = new TCHAR [dwBufferSize]; m_pchBuffer2 = new (std::nothrow) TCHAR [dwBufferSize];
if (!m_pchBuffer2) goto Abort; if (!m_pchBuffer2) goto Abort;
m_pchBuffer2[dwBufferSize-1] = 0; m_pchBuffer2[dwBufferSize-1] = 0;
@ -972,13 +972,13 @@ Abort:
if (m_hStdOut != INVALID_HANDLE_VALUE) VERIFY(CloseHandle(m_hStdOut)); if (m_hStdOut != INVALID_HANDLE_VALUE) VERIFY(CloseHandle(m_hStdOut));
m_hStdOut = INVALID_HANDLE_VALUE; m_hStdOut = INVALID_HANDLE_VALUE;
if (m_pchBuffer) delete m_pchBuffer; if (m_pchBuffer) delete[] m_pchBuffer;
m_pchBuffer = NULL; m_pchBuffer = NULL;
if (m_pchBuffer1) delete m_pchBuffer1; if (m_pchBuffer1) delete[] m_pchBuffer1;
m_pchBuffer1 = NULL; m_pchBuffer1 = NULL;
if (m_pchBuffer2) delete m_pchBuffer2; if (m_pchBuffer2) delete[] m_pchBuffer2;
m_pchBuffer2 = NULL; m_pchBuffer2 = NULL;
m_dwBufferSize = 0; m_dwBufferSize = 0;

View file

@ -32,7 +32,7 @@
CPrompt::CPrompt(CRegistryTree& rTree, HRESULT& rhr):m_rTree(rTree) CPrompt::CPrompt(CRegistryTree& rTree, HRESULT& rhr):m_rTree(rTree)
{ {
m_pszPrompt = new TCHAR[_tcslen(DEFAULT_PROMPT)+1]; m_pszPrompt = new (std::nothrow) TCHAR[_tcslen(DEFAULT_PROMPT)+1];
if (!m_pszPrompt) if (!m_pszPrompt)
{ {
rhr = E_OUTOFMEMORY; rhr = E_OUTOFMEMORY;
@ -50,7 +50,7 @@ HRESULT CPrompt::SetPrompt(LPCTSTR pszPrompt)
return E_UNEXPECTED; return E_UNEXPECTED;
} }
m_pszPrompt = new TCHAR[_tcslen(pszPrompt)+1]; m_pszPrompt = new (std::nothrow) TCHAR[_tcslen(pszPrompt)+1];
if (!m_pszPrompt) if (!m_pszPrompt)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
@ -62,7 +62,7 @@ HRESULT CPrompt::SetPrompt(LPCTSTR pszPrompt)
CPrompt::~CPrompt() CPrompt::~CPrompt()
{ {
if (m_pszPrompt) if (m_pszPrompt)
delete m_pszPrompt; delete[] m_pszPrompt;
} }
void CPrompt::ShowPrompt(CConsole &rConsole) void CPrompt::ShowPrompt(CConsole &rConsole)

View file

@ -138,7 +138,7 @@ int main ()
CArgumentParser Parser; CArgumentParser Parser;
pSettings = new CSettings(); pSettings = new (std::nothrow) CSettings();
if (!pSettings) if (!pSettings)
{ {
_ftprintf(stderr,_T("Cannot initialize settings. Out of memory.\n")); _ftprintf(stderr,_T("Cannot initialize settings. Out of memory.\n"));
@ -152,7 +152,7 @@ int main ()
goto Abort; goto Abort;
} }
pPrompt = new CPrompt(Tree,hr); pPrompt = new (std::nothrow) CPrompt(Tree,hr);
if (!pPrompt) if (!pPrompt)
{ {
_ftprintf(stderr,_T("Cannot initialize prompt. Out of memory.\n")); _ftprintf(stderr,_T("Cannot initialize prompt. Out of memory.\n"));

View file

@ -70,7 +70,7 @@ HRESULT CRegistryKey::InitRoot(const TCHAR *pszMachineName)
{ // copy machine name { // copy machine name
size_t size = _tcslen(pszMachineName); size_t size = _tcslen(pszMachineName);
m_pszMachineName = new TCHAR [size+2]; m_pszMachineName = new (std::nothrow) TCHAR [size+2];
if (!m_pszMachineName) if (!m_pszMachineName)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
_tcscpy(m_pszMachineName,pszMachineName); _tcscpy(m_pszMachineName,pszMachineName);
@ -103,7 +103,7 @@ HRESULT CRegistryKey::Init(HKEY hKey, const TCHAR *pszPath, const TCHAR *pszKeyN
if (pszPath) if (pszPath)
size += _tcslen(pszPath); size += _tcslen(pszPath);
m_pszKeyName = new TCHAR [size+2]; m_pszKeyName = new (std::nothrow) TCHAR [size+2];
if (!m_pszKeyName) if (!m_pszKeyName)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
_stprintf(m_pszKeyName,_T("%s%s\\"),pszPath?pszPath:_T(""),pszKeyName); _stprintf(m_pszKeyName,_T("%s%s\\"),pszPath?pszPath:_T(""),pszKeyName);
@ -273,7 +273,7 @@ LONG CRegistryKey::OpenSubkey(REGSAM samDesired, const TCHAR *pszSubkeyName, CRe
{ {
const TCHAR *pszKeyName = GetKeyName(); const TCHAR *pszKeyName = GetKeyName();
size_t size = _tcslen(pszKeyName) + _tcslen(pszSubkeyName) + 1; size_t size = _tcslen(pszKeyName) + _tcslen(pszSubkeyName) + 1;
TCHAR *pszSubkeyFullName = new TCHAR [size]; TCHAR *pszSubkeyFullName = new (std::nothrow) TCHAR [size];
if (!pszSubkeyFullName) if (!pszSubkeyFullName)
{ {
nError = RegCloseKey(hKey); nError = RegCloseKey(hKey);
@ -283,7 +283,7 @@ LONG CRegistryKey::OpenSubkey(REGSAM samDesired, const TCHAR *pszSubkeyName, CRe
_tcscpy(pszSubkeyFullName,pszKeyName); _tcscpy(pszSubkeyFullName,pszKeyName);
_tcscat(pszSubkeyFullName,pszSubkeyName); _tcscat(pszSubkeyFullName,pszSubkeyName);
HRESULT hr = rKey.Init(hKey,GetKeyName(),pszSubkeyName,samDesired); HRESULT hr = rKey.Init(hKey,GetKeyName(),pszSubkeyName,samDesired);
delete pszSubkeyName; delete[] pszSubkeyName;
if (FAILED(hr)) if (FAILED(hr))
{ {
nError = RegCloseKey(hKey); nError = RegCloseKey(hKey);

View file

@ -64,7 +64,7 @@ CRegistryTree::CRegistryTree(const CRegistryTree& Tree)
CRegistryTree::~CRegistryTree() CRegistryTree::~CRegistryTree()
{ {
if (m_pszMachineName) if (m_pszMachineName)
delete m_pszMachineName; delete[] m_pszMachineName;
CNode *pNode; CNode *pNode;
while(m_pCurrentKey->m_pUp) while(m_pCurrentKey->m_pUp)
@ -98,7 +98,7 @@ BOOL CRegistryTree::ChangeCurrentKey(const TCHAR *pszRelativePath)
const TCHAR *pszSeps = _T("\\"); const TCHAR *pszSeps = _T("\\");
// Make buffer and copy relative path into it. // Make buffer and copy relative path into it.
TCHAR *pszBuffer = new TCHAR[_tcslen(pszRelativePath)+1]; TCHAR *pszBuffer = new (std::nothrow) TCHAR[_tcslen(pszRelativePath)+1];
if (!pszBuffer) if (!pszBuffer)
{ {
SetError(ERROR_OUTOFMEMORY); SetError(ERROR_OUTOFMEMORY);
@ -145,7 +145,7 @@ BOOL CRegistryTree::ChangeCurrentKey(const TCHAR *pszRelativePath)
return TRUE; return TRUE;
Abort: Abort:
delete pszBuffer; delete[] pszBuffer;
return FALSE; return FALSE;
} }
@ -179,7 +179,7 @@ BOOL CRegistryTree::SetMachineName(LPCTSTR pszMachineName)
{ {
// Delete previous machine name buffer if allocated. // Delete previous machine name buffer if allocated.
if (m_pszMachineName) if (m_pszMachineName)
delete m_pszMachineName; delete[] m_pszMachineName;
m_pszMachineName = NULL; m_pszMachineName = NULL;
m_Root.m_Key.InitRoot(); m_Root.m_Key.InitRoot();
@ -192,9 +192,9 @@ BOOL CRegistryTree::SetMachineName(LPCTSTR pszMachineName)
ASSERT(*pszMachineName); // No machine name. ASSERT(*pszMachineName); // No machine name.
TCHAR *pszNewMachineName = new TCHAR[_tcslen(pszMachineName)+3]; // two leading backslashes + terminating null TCHAR *pszNewMachineName = new (std::nothrow) TCHAR[_tcslen(pszMachineName)+3]; // two leading backslashes + terminating null
if (!pszMachineName) if (!pszNewMachineName)
{ {
SetError(ERROR_OUTOFMEMORY); SetError(ERROR_OUTOFMEMORY);
return FALSE; return FALSE;
@ -202,7 +202,7 @@ BOOL CRegistryTree::SetMachineName(LPCTSTR pszMachineName)
// Delete previous machine name buffer if allocated. // Delete previous machine name buffer if allocated.
if (m_pszMachineName) if (m_pszMachineName)
delete m_pszMachineName; delete[] m_pszMachineName;
m_pszMachineName = pszNewMachineName; m_pszMachineName = pszNewMachineName;
@ -283,7 +283,7 @@ BOOL CRegistryTree::DeleteSubkeys(CRegistryKey& rKey, const TCHAR *pszKeyPattern
return FALSE; return FALSE;
} }
TCHAR *pszSubkeyName = new TCHAR [dwMaxSubkeyNameLength]; TCHAR *pszSubkeyName = new (std::nothrow) TCHAR [dwMaxSubkeyNameLength];
rKey.InitSubkeyEnumeration(pszSubkeyName, dwMaxSubkeyNameLength); rKey.InitSubkeyEnumeration(pszSubkeyName, dwMaxSubkeyNameLength);
BOOL blnKeyDeleted = FALSE; BOOL blnKeyDeleted = FALSE;
while ((nError = rKey.GetNextSubkeyName()) == ERROR_SUCCESS) while ((nError = rKey.GetNextSubkeyName()) == ERROR_SUCCESS)
@ -393,7 +393,7 @@ void CRegistryTree::SetErrorCommandNAOnRoot(const TCHAR *pszCommand)
BOOL CRegistryTree::InternalChangeCurrentKey(const TCHAR *pszSubkeyName, REGSAM DesiredAccess) BOOL CRegistryTree::InternalChangeCurrentKey(const TCHAR *pszSubkeyName, REGSAM DesiredAccess)
{ {
size_t size = _tcslen(pszSubkeyName); size_t size = _tcslen(pszSubkeyName);
TCHAR *pszSubkeyNameBuffer = new TCHAR[size+3]; TCHAR *pszSubkeyNameBuffer = new (std::nothrow) TCHAR[size+3];
if (!pszSubkeyNameBuffer) if (!pszSubkeyNameBuffer)
{ {
SetError(_T("Cannot open key : %s%s\nError %d (%s)\n"), SetError(_T("Cannot open key : %s%s\nError %d (%s)\n"),
@ -409,7 +409,7 @@ BOOL CRegistryTree::InternalChangeCurrentKey(const TCHAR *pszSubkeyName, REGSAM
if (_tcscmp(pszSubkeyName,_T(".")) == 0) if (_tcscmp(pszSubkeyName,_T(".")) == 0)
{ {
delete pszSubkeyNameBuffer; delete[] pszSubkeyNameBuffer;
return TRUE; return TRUE;
} }
@ -421,7 +421,7 @@ BOOL CRegistryTree::InternalChangeCurrentKey(const TCHAR *pszSubkeyName, REGSAM
// We are on root // We are on root
ASSERT(m_pCurrentKey->m_pUp == NULL); ASSERT(m_pCurrentKey->m_pUp == NULL);
SetError(_T("Cannot open key. The root is not child.\n")); SetError(_T("Cannot open key. The root is not child.\n"));
delete pszSubkeyNameBuffer; delete[] pszSubkeyNameBuffer;
return FALSE; return FALSE;
} }
@ -429,13 +429,13 @@ BOOL CRegistryTree::InternalChangeCurrentKey(const TCHAR *pszSubkeyName, REGSAM
if (!m_pCurrentKey->m_pUp) if (!m_pCurrentKey->m_pUp)
{ {
SetInternalError(); SetInternalError();
delete pszSubkeyNameBuffer; delete[] pszSubkeyNameBuffer;
return FALSE; return FALSE;
} }
CNode *pNode = m_pCurrentKey; CNode *pNode = m_pCurrentKey;
m_pCurrentKey = m_pCurrentKey->m_pUp; m_pCurrentKey = m_pCurrentKey->m_pUp;
delete pNode; delete pNode;
delete pszSubkeyNameBuffer; delete[] pszSubkeyNameBuffer;
return TRUE; return TRUE;
} }
@ -444,20 +444,20 @@ BOOL CRegistryTree::InternalChangeCurrentKey(const TCHAR *pszSubkeyName, REGSAM
{ {
SetError(_T("Cannot open key : %s%s\nError %d (%s)\n"), SetError(_T("Cannot open key : %s%s\nError %d (%s)\n"),
GetCurrentPath(),pszSubkeyName,ERROR_OUTOFMEMORY,GetErrorDescription(ERROR_OUTOFMEMORY)); GetCurrentPath(),pszSubkeyName,ERROR_OUTOFMEMORY,GetErrorDescription(ERROR_OUTOFMEMORY));
delete pszSubkeyNameBuffer; delete[] pszSubkeyNameBuffer;
return FALSE; return FALSE;
} }
if (!InternalGetSubkey(pszSubkeyName,DesiredAccess,pNewKey->m_Key)) if (!InternalGetSubkey(pszSubkeyName,DesiredAccess,pNewKey->m_Key))
{ {
delete pNewKey; delete pNewKey;
delete pszSubkeyNameBuffer; delete[] pszSubkeyNameBuffer;
return FALSE; return FALSE;
} }
pNewKey->m_pUp = m_pCurrentKey; pNewKey->m_pUp = m_pCurrentKey;
m_pCurrentKey = pNewKey; m_pCurrentKey = pNewKey;
delete pszSubkeyNameBuffer; delete[] pszSubkeyNameBuffer;
return TRUE; return TRUE;
} }
@ -483,7 +483,7 @@ BOOL CRegistryTree::InternalGetSubkey(const TCHAR *pszSubkeyName, REGSAM Desired
if (nError != ERROR_SUCCESS) if (nError != ERROR_SUCCESS)
goto SkipCaseUpdate; goto SkipCaseUpdate;
pszSubkeyNameCaseUpdated = new TCHAR [dwMaxSubkeyNameLength]; pszSubkeyNameCaseUpdated = new (std::nothrow) TCHAR [dwMaxSubkeyNameLength];
m_pCurrentKey->m_Key.InitSubkeyEnumeration(pszSubkeyNameCaseUpdated, dwMaxSubkeyNameLength); m_pCurrentKey->m_Key.InitSubkeyEnumeration(pszSubkeyNameCaseUpdated, dwMaxSubkeyNameLength);
while ((nError = m_pCurrentKey->m_Key.GetNextSubkeyName()) == ERROR_SUCCESS) while ((nError = m_pCurrentKey->m_Key.GetNextSubkeyName()) == ERROR_SUCCESS)
if (_tcsicmp(pszSubkeyNameCaseUpdated, pszSubkeyName) == 0) if (_tcsicmp(pszSubkeyNameCaseUpdated, pszSubkeyName) == 0)
@ -491,7 +491,7 @@ BOOL CRegistryTree::InternalGetSubkey(const TCHAR *pszSubkeyName, REGSAM Desired
if (nError != ERROR_SUCCESS) if (nError != ERROR_SUCCESS)
{ {
delete pszSubkeyNameCaseUpdated; delete[] pszSubkeyNameCaseUpdated;
pszSubkeyNameCaseUpdated = NULL; pszSubkeyNameCaseUpdated = NULL;
} }
@ -513,7 +513,7 @@ SkipCaseUpdate:
goto Abort; goto Abort;
} }
delete pszSubkeyNameCaseUpdated; delete[] pszSubkeyNameCaseUpdated;
} }
else else
{ {
@ -535,7 +535,7 @@ SkipCaseUpdate:
return TRUE; return TRUE;
Abort: Abort:
if (pszSubkeyNameCaseUpdated) if (pszSubkeyNameCaseUpdated)
delete pszSubkeyNameCaseUpdated; delete[] pszSubkeyNameCaseUpdated;
if (hNewKey) if (hNewKey)
{ {
@ -611,7 +611,7 @@ BOOL CRegistryTree::GetKey(const TCHAR *pszRelativePath, REGSAM DesiredAccess, C
return FALSE; return FALSE;
} }
TCHAR *pszShortKeyName = new TCHAR [size+1]; TCHAR *pszShortKeyName = new (std::nothrow) TCHAR [size+1];
if (!pszShortKeyName) if (!pszShortKeyName)
{ {
SetError(ERROR_OUTOFMEMORY); SetError(ERROR_OUTOFMEMORY);
@ -624,6 +624,7 @@ BOOL CRegistryTree::GetKey(const TCHAR *pszRelativePath, REGSAM DesiredAccess, C
// change to parent key // change to parent key
if (!Tree.InternalChangeCurrentKey(_T(".."),READ_CONTROL)) if (!Tree.InternalChangeCurrentKey(_T(".."),READ_CONTROL))
{ {
delete[] pszShortKeyName;
ASSERT(FALSE); ASSERT(FALSE);
SetInternalError(); SetInternalError();
return FALSE; return FALSE;
@ -632,10 +633,12 @@ BOOL CRegistryTree::GetKey(const TCHAR *pszRelativePath, REGSAM DesiredAccess, C
// change back to target key // change back to target key
if (!Tree.InternalGetSubkey(pszShortKeyName,DesiredAccess,rKey)) if (!Tree.InternalGetSubkey(pszShortKeyName,DesiredAccess,rKey))
{ {
delete[] pszShortKeyName;
SetError(Tree.GetLastErrorDescription()); SetError(Tree.GetLastErrorDescription());
return FALSE; return FALSE;
} }
delete[] pszShortKeyName;
return TRUE; return TRUE;
} }

View file

@ -47,7 +47,7 @@ HRESULT CSettings::Clean()
{ {
if (m_pszPrompt) if (m_pszPrompt)
{ {
delete m_pszPrompt; delete[] m_pszPrompt;
m_pszPrompt = NULL; m_pszPrompt = NULL;
} }
@ -75,7 +75,7 @@ HRESULT CSettings::Load(LPCTSTR pszLoadKey)
nError = RegQueryValueEx(hKey,PROMPT_VALUE_NAME,NULL,&dwType,NULL,&dwSize); nError = RegQueryValueEx(hKey,PROMPT_VALUE_NAME,NULL,&dwType,NULL,&dwSize);
if (nError == ERROR_SUCCESS && dwType == REG_SZ) if (nError == ERROR_SUCCESS && dwType == REG_SZ)
{ {
m_pszPrompt = (TCHAR *) new BYTE[dwSize]; m_pszPrompt = (TCHAR *) new (std::nothrow) BYTE[dwSize];
if (!m_pszPrompt) if (!m_pszPrompt)
{ {
hr = E_OUTOFMEMORY; hr = E_OUTOFMEMORY;

View file

@ -226,7 +226,7 @@ CheckDACLArgument:
rConsole.Write(pchSID); rConsole.Write(pchSID);
rConsole.Write(_T("\n")); rConsole.Write(_T("\n"));
} }
delete pchSID; delete[] pchSID;
DWORD dwNameBufferLength, dwDomainNameBufferLength; DWORD dwNameBufferLength, dwDomainNameBufferLength;
dwNameBufferLength = 1024; dwNameBufferLength = 1024;
dwDomainNameBufferLength = 1024; dwDomainNameBufferLength = 1024;

View file

@ -147,7 +147,7 @@ CheckValueArgument:
return 0; return 0;
} }
TCHAR *pszValueName = new TCHAR[dwMaxValueNameLength]; TCHAR *pszValueName = new (std::nothrow) TCHAR[dwMaxValueNameLength];
if (!pszValueName) if (!pszValueName)
{ {
rConsole.Write("Out of memory."); rConsole.Write("Out of memory.");

View file

@ -200,7 +200,7 @@ CheckDirArgument:
if (nError != ERROR_SUCCESS) if (nError != ERROR_SUCCESS)
throw nError; throw nError;
TCHAR *pszSubkeyNameBuffer = new TCHAR[dwMaxSubkeyNameLength]; TCHAR *pszSubkeyNameBuffer = new (std::nothrow) TCHAR[dwMaxSubkeyNameLength];
if (!pszSubkeyNameBuffer) if (!pszSubkeyNameBuffer)
throw ERROR_OUTOFMEMORY; throw ERROR_OUTOFMEMORY;
@ -216,7 +216,7 @@ CheckDirArgument:
} }
} }
delete pszSubkeyNameBuffer; delete[] pszSubkeyNameBuffer;
if (nError != ERROR_NO_MORE_ITEMS) if (nError != ERROR_NO_MORE_ITEMS)
throw nError; throw nError;
@ -226,7 +226,7 @@ CheckDirArgument:
if (nError != ERROR_SUCCESS) if (nError != ERROR_SUCCESS)
throw nError; throw nError;
TCHAR *pchValueNameBuffer = new TCHAR[dwMaxValueNameBufferSize]; TCHAR *pchValueNameBuffer = new (std::nothrow) TCHAR[dwMaxValueNameBufferSize];
if (!pchValueNameBuffer) if (!pchValueNameBuffer)
throw ERROR_OUTOFMEMORY; throw ERROR_OUTOFMEMORY;
@ -259,7 +259,7 @@ CheckDirArgument:
} }
} }
delete pchValueNameBuffer; delete[] pchValueNameBuffer;
if (nError != ERROR_NO_MORE_ITEMS) if (nError != ERROR_NO_MORE_ITEMS)
throw nError; throw nError;

View file

@ -220,7 +220,7 @@ CheckSACLArgument:
goto Error; goto Error;
} }
pSecurityDescriptor = (PISECURITY_DESCRIPTOR) new unsigned char [dwSecurityDescriptorLength]; pSecurityDescriptor = (PISECURITY_DESCRIPTOR) new (std::nothrow) unsigned char [dwSecurityDescriptorLength];
if (!pSecurityDescriptor) if (!pSecurityDescriptor)
{ {
_tcsncpy(pszError_msg,_T("\nOut of memory.\n"),ERROR_MSG_BUFFER_SIZE-1); _tcsncpy(pszError_msg,_T("\nOut of memory.\n"),ERROR_MSG_BUFFER_SIZE-1);
@ -292,7 +292,7 @@ CheckSACLArgument:
BOOL blnRet = GetTextualSid(pSID,NULL,&dwSIDStringSize); BOOL blnRet = GetTextualSid(pSID,NULL,&dwSIDStringSize);
ASSERT(!blnRet); ASSERT(!blnRet);
ASSERT(GetLastError() == ERROR_INSUFFICIENT_BUFFER); ASSERT(GetLastError() == ERROR_INSUFFICIENT_BUFFER);
TCHAR *pszSID = new TCHAR[dwSIDStringSize]; TCHAR *pszSID = new (std::nothrow) TCHAR[dwSIDStringSize];
if (!pszSID) if (!pszSID)
{ {
@ -315,24 +315,25 @@ CheckSACLArgument:
rConsole.Write(pszSID); rConsole.Write(pszSID);
rConsole.Write(_T("\n")); rConsole.Write(_T("\n"));
} }
delete pszSID; delete[] pszSID;
TCHAR *pszName, *pszDomainName; TCHAR *pszName, *pszDomainName;
DWORD dwNameBufferLength, dwDomainNameBufferLength; DWORD dwNameBufferLength, dwDomainNameBufferLength;
dwNameBufferLength = 1024; dwNameBufferLength = 1024;
dwDomainNameBufferLength = 1024; dwDomainNameBufferLength = 1024;
pszName = new TCHAR [dwNameBufferLength]; pszName = new (std::nothrow) TCHAR [dwNameBufferLength];
if (!pszName) if (!pszName)
{ {
_tcsncpy(pszError_msg,_T("\nOut of memory.\n"),ERROR_MSG_BUFFER_SIZE-1); _tcsncpy(pszError_msg,_T("\nOut of memory.\n"),ERROR_MSG_BUFFER_SIZE-1);
goto Error; goto Error;
} }
pszDomainName = new TCHAR [dwDomainNameBufferLength]; pszDomainName = new (std::nothrow) TCHAR [dwDomainNameBufferLength];
if (!pszDomainName) if (!pszDomainName)
{ {
_tcsncpy(pszError_msg,_T("\nOut of memory.\n"),ERROR_MSG_BUFFER_SIZE-1); _tcsncpy(pszError_msg,_T("\nOut of memory.\n"),ERROR_MSG_BUFFER_SIZE-1);
delete[] pszName;
goto Error; goto Error;
} }
@ -420,6 +421,9 @@ CheckSACLArgument:
{ {
rConsole.Write(_T("\t\tKEY_QUERY_VALUE\n")); rConsole.Write(_T("\t\tKEY_QUERY_VALUE\n"));
} }
delete[] pszName;
delete[] pszDomainName;
} // for } // for
AbortDumpSACL: AbortDumpSACL:

View file

@ -395,7 +395,7 @@ CheckValueArgument:
SkipCommand: SkipCommand:
if (pDataBuffer) if (pDataBuffer)
delete pDataBuffer; delete[] pDataBuffer;
return 0; return 0;
CommandNAonRoot: CommandNAonRoot:

View file

@ -415,7 +415,7 @@ CheckValueArgument:
SkipValueCommand: SkipValueCommand:
if (pDataBuffer) if (pDataBuffer)
delete pDataBuffer; delete[] pDataBuffer;
return 0; return 0;
ValueCommandNAonRoot: ValueCommandNAonRoot:
rConsole.Write(VALUE_CMD COMMAND_NA_ON_ROOT); rConsole.Write(VALUE_CMD COMMAND_NA_ON_ROOT);

View file

@ -43,7 +43,7 @@ CShellCommandsLinkedList::~CShellCommandsLinkedList()
void CShellCommandsLinkedList::AddCommand(CShellCommand *pCommand) void CShellCommandsLinkedList::AddCommand(CShellCommand *pCommand)
{ {
// Create new node // Create new node
SNode *pNewNode = new SNode; SNode *pNewNode = new (std::nothrow) SNode;
if (pNewNode == NULL) if (pNewNode == NULL)
return; return;

View file

@ -39,7 +39,7 @@ CTextHistory::CTextHistory()
CTextHistory::~CTextHistory() CTextHistory::~CTextHistory()
{ {
if (m_pHistoryBuffer) delete m_pHistoryBuffer; if (m_pHistoryBuffer) delete[] m_pHistoryBuffer;
} }
BOOL CTextHistory::Init(DWORD dwMaxHistoryLineSize, DWORD dwMaxHistoryLines) BOOL CTextHistory::Init(DWORD dwMaxHistoryLineSize, DWORD dwMaxHistoryLines)
@ -49,13 +49,13 @@ BOOL CTextHistory::Init(DWORD dwMaxHistoryLineSize, DWORD dwMaxHistoryLines)
ASSERT(FALSE); ASSERT(FALSE);
return FALSE; return FALSE;
} }
if (m_pHistoryBuffer) delete m_pHistoryBuffer; if (m_pHistoryBuffer) delete[] m_pHistoryBuffer;
m_dwFirstHistoryIndex = 0; m_dwFirstHistoryIndex = 0;
m_dwLastHistoryIndex = 0; m_dwLastHistoryIndex = 0;
m_dwHisoryFull = 0; m_dwHisoryFull = 0;
m_dwMaxHistoryLines = dwMaxHistoryLines; m_dwMaxHistoryLines = dwMaxHistoryLines;
m_dwMaxHistoryLineSize = dwMaxHistoryLineSize; m_dwMaxHistoryLineSize = dwMaxHistoryLineSize;
m_pHistoryBuffer = new TCHAR [m_dwMaxHistoryLines*dwMaxHistoryLineSize]; m_pHistoryBuffer = new (std::nothrow) TCHAR [m_dwMaxHistoryLines*dwMaxHistoryLineSize];
if (!m_pHistoryBuffer) return FALSE; if (!m_pHistoryBuffer) return FALSE;
return TRUE; return TRUE;
} }

View file

@ -27,7 +27,7 @@
#include <winuser.h> #include <winuser.h>
#include <winreg.h> #include <winreg.h>
#include <assert.h> #include <cassert>
#define ASSERT assert #define ASSERT assert
#ifdef _DEBUG #ifdef _DEBUG
#define VERIFY ASSERT #define VERIFY ASSERT
@ -36,11 +36,12 @@
#endif #endif
#include <conio.h> #include <conio.h>
#include <limits.h> #include <climits>
#include <tchar.h> #include <tchar.h>
#include <stdio.h> #include <cstdio>
#include <stdlib.h> #include <cstdlib>
#include <ctype.h> #include <ctype.h>
#include <new>
// INHERITED_ACE is from windows 2000 // INHERITED_ACE is from windows 2000
#ifndef INHERITED_ACE #ifndef INHERITED_ACE