Hello Arjan,

In several cases in cpu/* we have NULL check for operator new return, which
is not correct since new will throw in case of error:

606         state = new(std::nothrow) struct frequency;
607
608         if (!state)
609             return;

To make NULL check legal we shall use non-throwing operator new
new(std::nothrow)

(http://www.cplusplus.com/reference/std/new/nothrow_t/)

We can change operator new to non-throwing one or we can drop `if (!state)'
check and make allocation exceptions fatal (unhandled exception) like we
do in other places.

---

 cpu/abstract_cpu.cpp |    4 ++--
 cpu/cpu_core.cpp     |    2 +-
 cpu/cpu_linux.cpp    |    2 +-
 cpu/cpu_package.cpp  |    2 +-
 cpu/intel_cpus.cpp   |    6 +++---
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/cpu/abstract_cpu.cpp b/cpu/abstract_cpu.cpp
index fe4f3a0..2296cd8 100644
--- a/cpu/abstract_cpu.cpp
+++ b/cpu/abstract_cpu.cpp
@@ -135,7 +135,7 @@ void abstract_cpu::insert_cstate(const char *linux_name, 
const char *human_name,
        struct idle_state *state;
        const char *c;
 
-       state = new struct idle_state;
+       state = new(std::nothrow) struct idle_state;
 
        if (!state)
                return;
@@ -251,7 +251,7 @@ void abstract_cpu::insert_pstate(uint64_t freq, const char 
*human_name, uint64_t
 {
        struct frequency *state;
 
-       state = new struct frequency;
+       state = new(std::nothrow) struct frequency;
 
        if (!state)
                return;
diff --git a/cpu/cpu_core.cpp b/cpu/cpu_core.cpp
index d203ffc..579a1d9 100644
--- a/cpu/cpu_core.cpp
+++ b/cpu/cpu_core.cpp
@@ -101,7 +101,7 @@ void cpu_core::account_freq(uint64_t freq, uint64_t 
duration)
 
 
        if (!state) {
-               state = new struct frequency;
+               state = new(std::nothrow) struct frequency;
 
                if (!state)
                        return;
diff --git a/cpu/cpu_linux.cpp b/cpu/cpu_linux.cpp
index c8dea7e..a47161c 100644
--- a/cpu/cpu_linux.cpp
+++ b/cpu/cpu_linux.cpp
@@ -314,7 +314,7 @@ void cpu_linux::account_freq(uint64_t freq, uint64_t 
duration)
        }
 
        if (!state) {
-               state = new struct frequency;
+               state = new(std::nothrow) struct frequency;
 
                if (!state)
                        return;
diff --git a/cpu/cpu_package.cpp b/cpu/cpu_package.cpp
index 7f4760a..cdd751e 100644
--- a/cpu/cpu_package.cpp
+++ b/cpu/cpu_package.cpp
@@ -130,7 +130,7 @@ void cpu_package::account_freq(uint64_t freq, uint64_t 
duration)
 
 
        if (!state) {
-               state = new struct frequency;
+               state = new(std::nothrow) struct frequency;
 
                if (!state)
                        return;
diff --git a/cpu/intel_cpus.cpp b/cpu/intel_cpus.cpp
index 44a178a..e59cd76 100644
--- a/cpu/intel_cpus.cpp
+++ b/cpu/intel_cpus.cpp
@@ -184,7 +184,7 @@ void nhm_core::account_freq(uint64_t freq, uint64_t 
duration)
 
 
        if (!state) {
-               state = new struct frequency;
+               state = new(std::nothrow) struct frequency;
 
                if (!state)
                        return;
@@ -402,7 +402,7 @@ void nhm_package::account_freq(uint64_t freq, uint64_t 
duration)
 
 
        if (!state) {
-               state = new struct frequency;
+               state = new(std::nothrow) struct frequency;
 
                if (!state)
                        return;
@@ -603,7 +603,7 @@ void nhm_cpu::account_freq(uint64_t freq, uint64_t duration)
        }
 
        if (!state) {
-               state = new struct frequency;
+               state = new(std::nothrow) struct frequency;
 
                if (!state)
                        return;

_______________________________________________
Discuss mailing list
Discuss@lesswatts.org
http://lists.lesswatts.org/listinfo/discuss

Reply via email to