Debugger: Fix CID 1223239.

- Rework part of report generator to add missing memory allocation
  error checks.
This commit is contained in:
Rene Gollent
2014-09-06 16:48:30 -04:00
parent ece6f8ba5d
commit 7b5a544edb
@@ -16,6 +16,7 @@
#include "Architecture.h" #include "Architecture.h"
#include "AreaInfo.h" #include "AreaInfo.h"
#include "AutoDeleter.h"
#include "CpuState.h" #include "CpuState.h"
#include "DebuggerInterface.h" #include "DebuggerInterface.h"
#include "DisassembledCode.h" #include "DisassembledCode.h"
@@ -235,18 +236,20 @@ DebugReportGenerator::_GenerateReportHeader(BFile& _output)
fTeam->Name(), fTeam->ID()); fTeam->Name(), fTeam->ID());
WRITE_AND_CHECK(_output, data); WRITE_AND_CHECK(_output, data);
SystemInfo sysInfo;
uint32 topologyNodeCount = 0;
cpu_topology_node_info* topology = NULL;
get_cpu_topology_info(NULL, &topologyNodeCount);
if (topologyNodeCount != 0)
topology = new cpu_topology_node_info[topologyNodeCount];
get_cpu_topology_info(topology, &topologyNodeCount);
cpu_platform platform = B_CPU_UNKNOWN; cpu_platform platform = B_CPU_UNKNOWN;
cpu_vendor cpuVendor = B_CPU_VENDOR_UNKNOWN; cpu_vendor cpuVendor = B_CPU_VENDOR_UNKNOWN;
uint32 cpuModel = 0; uint32 cpuModel = 0;
uint32 topologyNodeCount = 0;
cpu_topology_node_info* topology = NULL;
get_cpu_topology_info(NULL, &topologyNodeCount);
if (topologyNodeCount != 0) {
topology = new(std::nothrow) cpu_topology_node_info[topologyNodeCount];
if (topology == NULL)
return B_NO_MEMORY;
BPrivate::ArrayDeleter<cpu_topology_node_info> deleter(topology);
get_cpu_topology_info(topology, &topologyNodeCount);
for (uint32 i = 0; i < topologyNodeCount; i++) { for (uint32 i = 0; i < topologyNodeCount; i++) {
switch (topology[i].type) { switch (topology[i].type) {
case B_TOPOLOGY_ROOT: case B_TOPOLOGY_ROOT:
@@ -265,7 +268,9 @@ DebugReportGenerator::_GenerateReportHeader(BFile& _output)
break; break;
} }
} }
}
SystemInfo sysInfo;
if (fDebuggerInterface->GetSystemInfo(sysInfo) == B_OK) { if (fDebuggerInterface->GetSystemInfo(sysInfo) == B_OK) {
const system_info &info = sysInfo.GetSystemInfo(); const system_info &info = sysInfo.GetSystemInfo();
data.SetToFormat("CPU(s): %" B_PRId32 "x %s %s\n", data.SetToFormat("CPU(s): %" B_PRId32 "x %s %s\n",
@@ -289,7 +294,6 @@ DebugReportGenerator::_GenerateReportHeader(BFile& _output)
WRITE_AND_CHECK(_output, data); WRITE_AND_CHECK(_output, data);
} }
delete[] topology;
return B_OK; return B_OK;
} }