From 7b5a544edb5f6fb31e60361f53ec8aef740c17e7 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Sat, 21 Jun 2014 22:06:06 -0400 Subject: [PATCH] Debugger: Fix CID 1223239. - Rework part of report generator to add missing memory allocation error checks. --- .../controllers/DebugReportGenerator.cpp | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/src/apps/debugger/controllers/DebugReportGenerator.cpp b/src/apps/debugger/controllers/DebugReportGenerator.cpp index dd09bde244..efb1517e44 100644 --- a/src/apps/debugger/controllers/DebugReportGenerator.cpp +++ b/src/apps/debugger/controllers/DebugReportGenerator.cpp @@ -16,6 +16,7 @@ #include "Architecture.h" #include "AreaInfo.h" +#include "AutoDeleter.h" #include "CpuState.h" #include "DebuggerInterface.h" #include "DisassembledCode.h" @@ -235,37 +236,41 @@ DebugReportGenerator::_GenerateReportHeader(BFile& _output) fTeam->Name(), fTeam->ID()); 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_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; + 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; - case B_TOPOLOGY_PACKAGE: - cpuVendor = topology[i].data.package.vendor; - break; + BPrivate::ArrayDeleter deleter(topology); + get_cpu_topology_info(topology, &topologyNodeCount); - case B_TOPOLOGY_CORE: - cpuModel = topology[i].data.core.model; - break; + for (uint32 i = 0; i < topologyNodeCount; i++) { + switch (topology[i].type) { + case B_TOPOLOGY_ROOT: + platform = topology[i].data.root.platform; + break; - default: - break; + case B_TOPOLOGY_PACKAGE: + 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) { const system_info &info = sysInfo.GetSystemInfo(); data.SetToFormat("CPU(s): %" B_PRId32 "x %s %s\n", @@ -289,7 +294,6 @@ DebugReportGenerator::_GenerateReportHeader(BFile& _output) WRITE_AND_CHECK(_output, data); } - delete[] topology; return B_OK; }