From 21e05c2aa7e56d892123ae5dc65684ec0456cdfa Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sun, 2 Dec 2018 02:47:55 +0100 Subject: [PATCH] do not throw dynamically allocated exceptions --- common/include/villas/cpuset.hpp | 2 +- common/lib/cpuset.cpp | 6 +++--- common/lib/kernel/kernel.cpp | 2 +- common/lib/kernel/rt.cpp | 6 +++--- common/lib/log.cpp | 6 +++--- common/lib/terminal.cpp | 6 +++--- common/lib/version.cpp | 4 ++-- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/common/include/villas/cpuset.hpp b/common/include/villas/cpuset.hpp index 4206cfe11..7bfe8a36a 100644 --- a/common/include/villas/cpuset.hpp +++ b/common/include/villas/cpuset.hpp @@ -50,7 +50,7 @@ public: setp = CPU_ALLOC(num_cpus); if (!setp) - throw new villas::RuntimeError("Failed to allocated memory"); + throw villas::RuntimeError("Failed to allocated memory"); zero(); } diff --git a/common/lib/cpuset.cpp b/common/lib/cpuset.cpp index 9f05573d8..d63bc9169 100644 --- a/common/lib/cpuset.cpp +++ b/common/lib/cpuset.cpp @@ -63,7 +63,7 @@ CpuSet::CpuSet(const std::string &str) : start = std::stoi(token, &endpos); if (token.begin() + endpos != token.end()) - throw new std::invalid_argument("Not a valid CPU set"); + throw std::invalid_argument("Not a valid CPU set"); if (start < num_cpus) set(start); @@ -72,14 +72,14 @@ CpuSet::CpuSet(const std::string &str) : start = std::stoi(token, &endpos); if (token.begin() + endpos != token.begin() + sep) - throw new std::invalid_argument("Not a valid CPU set"); + throw std::invalid_argument("Not a valid CPU set"); auto token2 = token.substr(endpos + 1); end = std::stoi(token2, &endpos); if (token2.begin() + endpos != token2.end()) - throw new std::invalid_argument("Not a valid CPU set"); + throw std::invalid_argument("Not a valid CPU set"); for (size_t i = start; i <= end && i < num_cpus; i++) set(i); diff --git a/common/lib/kernel/kernel.cpp b/common/lib/kernel/kernel.cpp index e8a557745..5637ea7ba 100644 --- a/common/lib/kernel/kernel.cpp +++ b/common/lib/kernel/kernel.cpp @@ -32,7 +32,7 @@ Version villas::kernel::getVersion() struct utsname uts; if (uname(&uts) < 0) - throw new SystemError("Failed to retrieve system identification"); + throw SystemError("Failed to retrieve system identification"); std::string rel = uts.release; diff --git a/common/lib/kernel/rt.cpp b/common/lib/kernel/rt.cpp index af8227822..482eb30eb 100644 --- a/common/lib/kernel/rt.cpp +++ b/common/lib/kernel/rt.cpp @@ -85,7 +85,7 @@ int lockMemory() #ifdef _POSIX_MEMLOCK ret = mlockall(MCL_CURRENT | MCL_FUTURE); if (ret) - throw new SystemError("Failed to lock memory"); + throw SystemError("Failed to lock memory"); #endif return 0; @@ -117,7 +117,7 @@ int setAffinity(int affinity) ret = sched_setaffinity(0, cset_pin.size(), cset_pin); if (ret) - throw new SystemError("Failed to set CPU affinity to {}", (std::string) cset_pin); + throw SystemError("Failed to set CPU affinity to {}", (std::string) cset_pin); logger->debug("Set affinity to {}", (std::string) cset_pin); @@ -133,7 +133,7 @@ int setPriority(int priority) ret = sched_setscheduler(0, SCHED_FIFO, ¶m); if (ret) - throw new SystemError("Failed to set real time priority"); + throw SystemError("Failed to set real time priority"); logger->debug("Task priority set to {}", priority); diff --git a/common/lib/log.cpp b/common/lib/log.cpp index 61adbc708..288d1e1ee 100644 --- a/common/lib/log.cpp +++ b/common/lib/log.cpp @@ -90,7 +90,7 @@ void Log::parse(json_t *cfg) "pattern", &pattern ); if (ret) - throw new JsonError(err); + throw JsonError(err); if (level) setLevel(level); @@ -109,7 +109,7 @@ void Log::parse(json_t *cfg) if (json_expressions) { if (!json_is_array(json_expressions)) - throw new ConfigError(json_expressions, "node-config.html#node-config-logging-expressions", "The 'expressions' setting must be a list of objects."); + throw ConfigError(json_expressions, "node-config.html#node-config-logging-expressions", "The 'expressions' setting must be a list of objects."); size_t i; json_t *json_expression; @@ -122,7 +122,7 @@ void Log::parse(json_t *cfg) "level", &lvl ); if (ret) - throw new JsonError(err); + throw JsonError(err); Logger logger = get(name); auto level = spdlog::level::from_str(lvl); diff --git a/common/lib/terminal.cpp b/common/lib/terminal.cpp index 9cf569e24..57f496755 100644 --- a/common/lib/terminal.cpp +++ b/common/lib/terminal.cpp @@ -45,12 +45,12 @@ Terminal::Terminal() ret = sigaction(SIGWINCH, &sa_resize, NULL); if (ret) - throw new SystemError("Failed to register signal handler"); + throw SystemError("Failed to register signal handler"); /* Try to get initial terminal dimensions */ ret = ioctl(STDERR_FILENO, TIOCGWINSZ, &window); if (ret) - throw new SystemError("Failed to get terminal dimensions"); + throw SystemError("Failed to get terminal dimensions"); } /* Fallback if for some reason we can not determine a prober window size */ @@ -67,7 +67,7 @@ void Terminal::resize(int, siginfo_t *, void *) ret = ioctl(STDERR_FILENO, TIOCGWINSZ, &window); if (ret) - throw new SystemError("Failed to get terminal dimensions"); + throw SystemError("Failed to get terminal dimensions"); Logger logger = logging.get("terminal"); diff --git a/common/lib/version.cpp b/common/lib/version.cpp index 66970b342..285c063d7 100644 --- a/common/lib/version.cpp +++ b/common/lib/version.cpp @@ -36,14 +36,14 @@ Version::Version(const std::string &str) auto comp = tokenize(str, "."); if (comp.size() > 3) - throw new std::invalid_argument("Not a valid version string"); + throw std::invalid_argument("Not a valid version string"); for (unsigned i = 0; i < 3; i++) { if (i < comp.size()) { components[i] = std::stoi(comp[i], &endpos, 10); if (comp[i].begin() + endpos != comp[i].end()) - throw new std::invalid_argument("Not a valid version string"); + throw std::invalid_argument("Not a valid version string"); } else components[i] = 0;