Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Clean up function exits.
Browse files Browse the repository at this point in the history
  • Loading branch information
adityamandaleeka committed Feb 19, 2016
1 parent d694dfc commit 9ecff63
Showing 1 changed file with 33 additions and 34 deletions.
67 changes: 33 additions & 34 deletions src/pal/src/misc/environ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,26 +692,26 @@ BOOL ResizeEnvironment(int newSize)
CPalThread * pthrCurrent = InternalGetCurrentThread();
InternalEnterCriticalSection(pthrCurrent, &gcsEnvironment);

if (newSize < palEnvironmentCount)
BOOL ret = FALSE;
if (newSize >= palEnvironmentCount)
{
ASSERT("ResizeEnvironment: New size < current count!\n");
return FALSE;
// If palEnvironment is null, realloc acts like malloc.
char **newEnvironment = (char**)realloc(palEnvironment, newSize * sizeof(char *));
if (newEnvironment != nullptr)
{
// realloc succeeded, so set palEnvironment to what it returned.
palEnvironment = newEnvironment;
palEnvironmentCapacity = newSize;
ret = TRUE;
}
}

// If palEnvironment is null, realloc acts like malloc.
char **newEnvironment = (char**)realloc(palEnvironment, newSize * sizeof(char *));
if (!newEnvironment)
else
{
return FALSE;
ASSERT("ResizeEnvironment: newSize < current palEnvironmentCount!\n");
}

// realloc succeeded, so set palEnvironment to what it returned.
palEnvironment = newEnvironment;
palEnvironmentCapacity = newSize;

InternalLeaveCriticalSection(pthrCurrent, &gcsEnvironment);

return TRUE;
return ret;
}

/*++
Expand Down Expand Up @@ -994,6 +994,8 @@ Note: This is called before debug channels are initialized, so it
BOOL
EnvironInitialize(void)
{
BOOL ret = FALSE;

InternalInitializeCriticalSection(&gcsEnvironment);

CPalThread * pthrCurrent = InternalGetCurrentThread();
Expand All @@ -1014,26 +1016,23 @@ EnvironInitialize(void)
// If there are no variables, we will still make room for 1 entry to
// store a nullptr there.
int initialSize = (variableCount == 0) ? 1 : variableCount * 2;
BOOL resizeRet = ResizeEnvironment(initialSize);
if (resizeRet == FALSE)
{
InternalLeaveCriticalSection(pthrCurrent, &gcsEnvironment);
return FALSE;
}

_ASSERTE(palEnvironment != nullptr);
for (int i = 0; i < variableCount; ++i)
ret = ResizeEnvironment(initialSize);
if (ret == TRUE)
{
palEnvironment[i] = strdup(sourceEnviron[i]);
palEnvironmentCount++;
}
_ASSERTE(palEnvironment != nullptr);
for (int i = 0; i < variableCount; ++i)
{
palEnvironment[i] = strdup(sourceEnviron[i]);
palEnvironmentCount++;
}

// Set the entry after the last variable to null to indicate the end.
palEnvironment[variableCount] = nullptr;
// Set the entry after the last variable to null to indicate the end.
palEnvironment[variableCount] = nullptr;
}

InternalLeaveCriticalSection(pthrCurrent, &gcsEnvironment);

return TRUE;
return ret;
}

/*++
Expand All @@ -1054,15 +1053,15 @@ _putenv( const char * envstring )
PERF_ENTRY(_putenv);
ENTRY( "_putenv( %p (%s) )\n", envstring ? envstring : "NULL", envstring ? envstring : "NULL") ;

if (!envstring)
if (envstring != nullptr)
{
ret = EnvironPutenv(envstring, TRUE) ? 0 : -1;
}
else
{
ERROR( "_putenv() called with NULL envstring!\n");
goto EXIT;
}

ret = EnvironPutenv(envstring, TRUE) ? 0 : -1;

EXIT:
LOGEXIT( "_putenv returning %d\n", ret);
PERF_EXIT(_putenv);
return ret;
Expand Down

0 comments on commit 9ecff63

Please sign in to comment.