summaryrefslogtreecommitdiff
path: root/src/pal
diff options
context:
space:
mode:
authorJan Vorlicek <janvorli@microsoft.com>2018-01-17 00:05:52 +0100
committerJan Kotas <jkotas@microsoft.com>2018-01-16 15:05:52 -0800
commit5424bc69242a3cead6e1ed84c442a178a1ec8fe7 (patch)
treea42217e62aca80f69d9f1b4ec0bf42e186935ed7 /src/pal
parent4c8a732b6c27c5bfbdf9aee488a22704c4eb58bd (diff)
downloadcoreclr-5424bc69242a3cead6e1ed84c442a178a1ec8fe7.tar.gz
coreclr-5424bc69242a3cead6e1ed84c442a178a1ec8fe7.tar.bz2
coreclr-5424bc69242a3cead6e1ed84c442a178a1ec8fe7.zip
Fix one missing check for NULL after malloc (#15877)
When making the last change to the numa.cpp, I have made a mistake and forgotten to check return value of one of the mallocs. This change fixes that and also changes the code pattern to use goto for the cleanup purposes instead of the nested ifs.
Diffstat (limited to 'src/pal')
-rw-r--r--src/pal/src/numa/numa.cpp43
1 files changed, 27 insertions, 16 deletions
diff --git a/src/pal/src/numa/numa.cpp b/src/pal/src/numa/numa.cpp
index 7690dc00e7..17b71abd89 100644
--- a/src/pal/src/numa/numa.cpp
+++ b/src/pal/src/numa/numa.cpp
@@ -117,26 +117,37 @@ BOOL
AllocateLookupArrays()
{
g_groupAndIndexToCpu = (short*)malloc(g_groupCount * MaxCpusPerGroup * sizeof(short));
- if (g_groupAndIndexToCpu != NULL)
+ if (g_groupAndIndexToCpu == NULL)
{
- g_cpuToAffinity = (CpuAffinity*)malloc(g_possibleCpuCount * sizeof(CpuAffinity));
- if (g_cpuToAffinity != NULL)
- {
- g_groupToCpuMask = (KAFFINITY*)malloc(g_groupCount * sizeof(KAFFINITY));
- if (g_groupToCpuMask != NULL)
- {
- g_groupToCpuCount = (BYTE*)malloc(g_groupCount * sizeof(BYTE));
- memset(g_groupAndIndexToCpu, 0xff, g_groupCount * MaxCpusPerGroup * sizeof(short));
- memset(g_cpuToAffinity, 0xff, g_possibleCpuCount * sizeof(CpuAffinity));
- memset(g_groupToCpuMask, 0, g_groupCount * sizeof(KAFFINITY));
- memset(g_groupToCpuCount, 0, g_groupCount * sizeof(BYTE));
+ goto FAILED;
+ }
- return TRUE;
- }
- }
+ g_cpuToAffinity = (CpuAffinity*)malloc(g_possibleCpuCount * sizeof(CpuAffinity));
+ if (g_cpuToAffinity == NULL)
+ {
+ goto FAILED;
}
- // One of the allocations have failed
+ g_groupToCpuMask = (KAFFINITY*)malloc(g_groupCount * sizeof(KAFFINITY));
+ if (g_groupToCpuMask == NULL)
+ {
+ goto FAILED;
+ }
+
+ g_groupToCpuCount = (BYTE*)malloc(g_groupCount * sizeof(BYTE));
+ if (g_groupToCpuCount == NULL)
+ {
+ goto FAILED;
+ }
+
+ memset(g_groupAndIndexToCpu, 0xff, g_groupCount * MaxCpusPerGroup * sizeof(short));
+ memset(g_cpuToAffinity, 0xff, g_possibleCpuCount * sizeof(CpuAffinity));
+ memset(g_groupToCpuMask, 0, g_groupCount * sizeof(KAFFINITY));
+ memset(g_groupToCpuCount, 0, g_groupCount * sizeof(BYTE));
+
+ return TRUE;
+
+FAILED:
FreeLookupArrays();
return FALSE;