mirror of
https://github.com/reactos/reactos.git
synced 2026-05-31 16:31:07 +08:00
[CMD] Add missing memory allocation NULL checks (#161). CORE-8304
Adapted from a patch by Jacob S. Preciado. Bring also the code suggestions emitted during review.
This commit is contained in:
@@ -50,6 +50,12 @@ INT cmd_path (LPTSTR param)
|
||||
LPTSTR pszBuffer;
|
||||
|
||||
pszBuffer = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
|
||||
if (!pszBuffer)
|
||||
{
|
||||
WARN("Cannot allocate memory for pszBuffer!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
dwBuffer = GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE);
|
||||
if (dwBuffer == 0)
|
||||
{
|
||||
@@ -61,8 +67,9 @@ INT cmd_path (LPTSTR param)
|
||||
{
|
||||
LPTSTR pszOldBuffer = pszBuffer;
|
||||
pszBuffer = (LPTSTR)cmd_realloc (pszBuffer, dwBuffer * sizeof (TCHAR));
|
||||
if (pszBuffer == NULL)
|
||||
if (!pszBuffer)
|
||||
{
|
||||
WARN("Cannot reallocate memory for pszBuffer!\n");
|
||||
cmd_free(pszOldBuffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user