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,37 +236,41 @@ 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;
for (uint32 i = 0; i < topologyNodeCount; i++) { uint32 topologyNodeCount = 0;
switch (topology[i].type) { cpu_topology_node_info* topology = NULL;
case B_TOPOLOGY_ROOT: get_cpu_topology_info(NULL, &topologyNodeCount);
platform = topology[i].data.root.platform; if (topologyNodeCount != 0) {
break; topology = new(std::nothrow) cpu_topology_node_info[topologyNodeCount];
if (topology == NULL)
return B_NO_MEMORY;
case B_TOPOLOGY_PACKAGE: BPrivate::ArrayDeleter<cpu_topology_node_info> deleter(topology);
cpuVendor = topology[i].data.package.vendor; get_cpu_topology_info(topology, &topologyNodeCount);
break;
case B_TOPOLOGY_CORE: for (uint32 i = 0; i < topologyNodeCount; i++) {
cpuModel = topology[i].data.core.model; switch (topology[i].type) {
break; case B_TOPOLOGY_ROOT:
platform = topology[i].data.root.platform;
break;
default: case B_TOPOLOGY_PACKAGE:
break; cpuVendor = topology[i].data.package.vendor;
break;
case B_TOPOLOGY_CORE:
cpuModel = topology[i].data.core.model;
break;
default:
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;
} }