Skip to content

Commit

Permalink
Debugger: Fix CID 1223239.
Browse files Browse the repository at this point in the history
- Rework part of report generator to add missing memory allocation
  error checks.
  • Loading branch information
anevilyak committed Sep 6, 2014
1 parent ece6f8b commit 7b5a544
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions src/apps/debugger/controllers/DebugReportGenerator.cpp
Expand Up @@ -16,6 +16,7 @@

#include "Architecture.h"
#include "AreaInfo.h"
#include "AutoDeleter.h"
#include "CpuState.h"
#include "DebuggerInterface.h"
#include "DisassembledCode.h"
Expand Down Expand Up @@ -235,37 +236,41 @@ DebugReportGenerator::_GenerateReportHeader(BFile& _output)
fTeam->Name(), fTeam->ID());
WRITE_AND_CHECK(_output, data);

SystemInfo sysInfo;

cpu_platform platform = B_CPU_UNKNOWN;
cpu_vendor cpuVendor = B_CPU_VENDOR_UNKNOWN;
uint32 cpuModel = 0;
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);
if (topologyNodeCount != 0) {
topology = new(std::nothrow) cpu_topology_node_info[topologyNodeCount];
if (topology == NULL)
return B_NO_MEMORY;

cpu_platform platform = B_CPU_UNKNOWN;
cpu_vendor cpuVendor = B_CPU_VENDOR_UNKNOWN;
uint32 cpuModel = 0;
for (uint32 i = 0; i < topologyNodeCount; i++) {
switch (topology[i].type) {
case B_TOPOLOGY_ROOT:
platform = topology[i].data.root.platform;
break;
BPrivate::ArrayDeleter<cpu_topology_node_info> deleter(topology);
get_cpu_topology_info(topology, &topologyNodeCount);

case B_TOPOLOGY_PACKAGE:
cpuVendor = topology[i].data.package.vendor;
break;
for (uint32 i = 0; i < topologyNodeCount; i++) {
switch (topology[i].type) {
case B_TOPOLOGY_ROOT:
platform = topology[i].data.root.platform;
break;

case B_TOPOLOGY_CORE:
cpuModel = topology[i].data.core.model;
break;
case B_TOPOLOGY_PACKAGE:
cpuVendor = topology[i].data.package.vendor;
break;

default:
break;
case B_TOPOLOGY_CORE:
cpuModel = topology[i].data.core.model;
break;

default:
break;
}
}
}

SystemInfo sysInfo;
if (fDebuggerInterface->GetSystemInfo(sysInfo) == B_OK) {
const system_info &info = sysInfo.GetSystemInfo();
data.SetToFormat("CPU(s): %" B_PRId32 "x %s %s\n",
Expand All @@ -289,7 +294,6 @@ DebugReportGenerator::_GenerateReportHeader(BFile& _output)
WRITE_AND_CHECK(_output, data);
}

delete[] topology;
return B_OK;
}

Expand Down

0 comments on commit 7b5a544

Please sign in to comment.