diff --git a/broker/core/inc/com/centreon/broker/mapping/entry.hh b/broker/core/inc/com/centreon/broker/mapping/entry.hh index 052c4fad865..c194b6a8fa4 100644 --- a/broker/core/inc/com/centreon/broker/mapping/entry.hh +++ b/broker/core/inc/com/centreon/broker/mapping/entry.hh @@ -239,14 +239,7 @@ class entry { other._source = nullptr; } - ~entry() noexcept { - // This is not the better fix, but entries are static objects - // only destroyed at the end of the program. - // if (_source) { - // delete _source; - // _source = nullptr; - // } - } + ~entry() noexcept = default; entry& operator=(entry const&) = delete; uint32_t get_attribute() const { return _attribute; } bool get_bool(const io::data& d) const; diff --git a/broker/core/src/database/mysql_stmt.cc b/broker/core/src/database/mysql_stmt.cc index 27bcb04e4c4..57e3c77d283 100644 --- a/broker/core/src/database/mysql_stmt.cc +++ b/broker/core/src/database/mysql_stmt.cc @@ -429,7 +429,7 @@ void mysql_stmt::operator<<(io::data const& d) { void mysql_stmt::bind_value_as_i32(int range, int value) { if (!_bind) - _bind.reset(new database::mysql_bind(_param_count)); + _bind = std::make_unique(_param_count); _bind->set_value_as_i32(range, value); } @@ -458,7 +458,7 @@ void mysql_stmt::bind_value_as_i32(std::string const& name, int value) { void mysql_stmt::bind_value_as_u32(int range, uint32_t value) { if (!_bind) - _bind.reset(new database::mysql_bind(_param_count)); + _bind = std::make_unique(_param_count); _bind->set_value_as_u32(range, value); } @@ -493,7 +493,7 @@ void mysql_stmt::bind_value_as_u32(std::string const& name, uint32_t value) { */ void mysql_stmt::bind_value_as_i64(int range, int64_t value) { if (!_bind) - _bind.reset(new database::mysql_bind(_param_count)); + _bind = std::make_unique(_param_count); _bind->set_value_as_i64(range, value); } @@ -534,7 +534,7 @@ void mysql_stmt::bind_value_as_i64(std::string const& name, int64_t value) { */ void mysql_stmt::bind_value_as_u64(int range, uint64_t value) { if (!_bind) - _bind.reset(new database::mysql_bind(_param_count)); + _bind = std::make_unique(_param_count); _bind->set_value_as_u64(range, value); } @@ -575,7 +575,7 @@ void mysql_stmt::bind_value_as_u64(std::string const& name, uint64_t value) { */ void mysql_stmt::bind_value_as_f32(int range, float value) { if (!_bind) - _bind.reset(new database::mysql_bind(_param_count)); + _bind = std::make_unique(_param_count); _bind->set_value_as_f32(range, value); } @@ -610,7 +610,7 @@ void mysql_stmt::bind_value_as_f32(std::string const& name, float value) { */ void mysql_stmt::bind_value_as_f64(int range, double value) { if (!_bind) - _bind.reset(new database::mysql_bind(_param_count)); + _bind = std::make_unique(_param_count); _bind->set_value_as_f64(range, value); } @@ -639,7 +639,7 @@ void mysql_stmt::bind_value_as_f64(std::string const& name, double value) { void mysql_stmt::bind_value_as_tiny(int range, char value) { if (!_bind) - _bind.reset(new database::mysql_bind(_param_count)); + _bind = std::make_unique(_param_count); _bind->set_value_as_tiny(range, value); } @@ -668,7 +668,7 @@ void mysql_stmt::bind_value_as_tiny(std::string const& name, char value) { void mysql_stmt::bind_value_as_bool(int range, bool value) { if (!_bind) - _bind.reset(new database::mysql_bind(_param_count)); + _bind = std::make_unique(_param_count); _bind->set_value_as_bool(range, value); } @@ -697,7 +697,7 @@ void mysql_stmt::bind_value_as_bool(std::string const& name, bool value) { void mysql_stmt::bind_value_as_str(int range, const fmt::string_view& value) { if (!_bind) - _bind.reset(new database::mysql_bind(_param_count)); + _bind = std::make_unique(_param_count); _bind->set_value_as_str(range, value); } @@ -726,7 +726,7 @@ void mysql_stmt::bind_value_as_str(std::string const& name, void mysql_stmt::bind_value_as_null(int range) { if (!_bind) - _bind.reset(new database::mysql_bind(_param_count)); + _bind = std::make_unique(_param_count); _bind->set_value_as_null(range); } diff --git a/engine/src/anomalydetection.cc b/engine/src/anomalydetection.cc index f5253fc3eb4..17efcca0f86 100644 --- a/engine/src/anomalydetection.cc +++ b/engine/src/anomalydetection.cc @@ -638,10 +638,10 @@ int anomalydetection::run_async_check(int check_options, without_thresholds = ""; // Init check result info. - std::unique_ptr check_result_info( - new check_result(service_check, this, checkable::check_active, - check_options, reschedule_check, latency, start_time, - start_time, false, true, service::state_ok, "")); + auto check_result_info = std::make_unique( + service_check, this, checkable::check_active, check_options, + reschedule_check, latency, start_time, start_time, false, true, + service::state_ok, ""); oss.str(""); oss.setf(std::ios_base::fixed, std::ios_base::floatfield); diff --git a/engine/src/broker/compatibility.cc b/engine/src/broker/compatibility.cc index 94ed1a52463..56fd85781c1 100644 --- a/engine/src/broker/compatibility.cc +++ b/engine/src/broker/compatibility.cc @@ -72,7 +72,7 @@ void compatibility::copyright_module(broker::handle* mod) { void compatibility::create_module(broker::handle* mod) { if (mod) { // Allocate memory. - std::unique_ptr new_module(new nebmodule); + auto new_module = std::make_unique(); // Module parameters. new_module->filename = string::dup(mod->get_filename()); diff --git a/engine/src/broker/handle.cc b/engine/src/broker/handle.cc index b51293545ba..aecba921917 100644 --- a/engine/src/broker/handle.cc +++ b/engine/src/broker/handle.cc @@ -196,7 +196,7 @@ void handle::open() { return; try { - _handle = std::shared_ptr(new library(_filename)); + _handle = std::make_shared(_filename); _handle->load(); int api_version(*static_cast(_handle->resolve("__neb_api_version"))); diff --git a/engine/src/broker/loader.cc b/engine/src/broker/loader.cc index 5e35d662929..3a0efb136d4 100644 --- a/engine/src/broker/loader.cc +++ b/engine/src/broker/loader.cc @@ -46,7 +46,7 @@ using namespace com::centreon::engine::logging; */ std::shared_ptr loader::add_module(std::string const& filename, std::string const& args) { - std::shared_ptr module(new handle(filename, args)); + auto module = std::make_shared(filename, args); _modules.push_back(module); return module; } diff --git a/engine/src/commands/commands.cc b/engine/src/commands/commands.cc index 5deb53424e3..eb187e613f3 100644 --- a/engine/src/commands/commands.cc +++ b/engine/src/commands/commands.cc @@ -217,10 +217,10 @@ int cmd_add_comment(int cmd, time_t entry_time, char* args) { return ERROR; /* add the comment */ - std::shared_ptr com{new comment( + auto com = std::make_shared( (cmd == CMD_ADD_HOST_COMMENT) ? comment::host : comment::service, comment::user, temp_host->get_host_id(), service_id, entry_time, user, - comment_data, persistent, comment::external, false, (time_t)0)}; + comment_data, persistent, comment::external, false, (time_t)0); uint64_t comment_id = com->get_comment_id(); comment::comments.insert({comment_id, com}); log_v2::external_command()->trace("{}, comment_id: {}, data: {}", diff --git a/engine/src/commands/connector.cc b/engine/src/commands/connector.cc index 7ed2c2fb9f2..dd80987652b 100644 --- a/engine/src/commands/connector.cc +++ b/engine/src/commands/connector.cc @@ -131,7 +131,7 @@ uint64_t connector::run(const std::string& processed_cmd, // Set query informations. uint64_t command_id(get_uniq_id()); - std::shared_ptr info(new query_info); + auto info = std::make_shared(); info->processed_cmd = processed_cmd; info->start_time = timestamp::now(); info->timeout = timeout; @@ -197,7 +197,7 @@ void connector::run(const std::string& processed_cmd, // Set query informations. uint64_t command_id(get_uniq_id()); - std::shared_ptr info(new query_info); + auto info = std::make_shared(); info->processed_cmd = processed_cmd; info->start_time = timestamp::now(); info->timeout = timeout; diff --git a/engine/src/configuration/applier/command.cc b/engine/src/configuration/applier/command.cc index 6020e345b41..749f79a642b 100644 --- a/engine/src/configuration/applier/command.cc +++ b/engine/src/configuration/applier/command.cc @@ -126,8 +126,8 @@ void applier::command::modify_object(configuration::command const& obj) { // not referenced anywhere, only ::command objects are. commands::command::commands.erase(obj.command_name()); if (obj.connector().empty()) { - std::shared_ptr raw{new commands::raw( - obj.command_name(), obj.command_line(), &checks::checker::instance())}; + auto raw = std::make_shared( + obj.command_name(), obj.command_line(), &checks::checker::instance()); commands::command::commands[raw->get_name()] = raw; } else { connector_map::iterator found_con{ diff --git a/engine/src/configuration/applier/connector.cc b/engine/src/configuration/applier/connector.cc index 3a2b22e3c26..08561a60c18 100644 --- a/engine/src/configuration/applier/connector.cc +++ b/engine/src/configuration/applier/connector.cc @@ -60,8 +60,8 @@ void applier::connector::add_object(configuration::connector const& obj) { config->connectors().insert(obj); // Create connector. - std::shared_ptr cmd(new commands::connector( - obj.connector_name(), processed_cmd, &checks::checker::instance())); + auto cmd = std::make_shared( + obj.connector_name(), processed_cmd, &checks::checker::instance()); commands::connector::connectors[obj.connector_name()] = cmd; } diff --git a/engine/src/configuration/applier/contactgroup.cc b/engine/src/configuration/applier/contactgroup.cc index dc7d3021e43..86a82f74507 100644 --- a/engine/src/configuration/applier/contactgroup.cc +++ b/engine/src/configuration/applier/contactgroup.cc @@ -84,8 +84,7 @@ void applier::contactgroup::add_object(configuration::contactgroup const& obj) { config->contactgroups().insert(obj); // Create contact group. - std::shared_ptr cg{new engine::contactgroup(obj)}; - + auto cg = std::make_shared(obj); for (set_string::const_iterator it(obj.members().begin()), end(obj.members().end()); it != end; ++it) { diff --git a/engine/src/configuration/applier/host.cc b/engine/src/configuration/applier/host.cc index 423d8e24f02..aad3189d4c5 100644 --- a/engine/src/configuration/applier/host.cc +++ b/engine/src/configuration/applier/host.cc @@ -59,7 +59,7 @@ void applier::host::add_object(configuration::host const& obj) { config->hosts().insert(obj); // Create host. - std::shared_ptr h{new engine::host( + auto h = std::make_shared( obj.host_id(), obj.host_name(), obj.display_name(), obj.alias(), obj.address(), obj.check_period(), static_cast(obj.initial_state()), @@ -95,7 +95,7 @@ void applier::host::add_object(configuration::host const& obj) { obj.have_coords_3d(), true, // should_be_drawn, enabled by Nagios obj.retain_status_information(), obj.retain_nonstatus_information(), - obj.obsess_over_host(), obj.timezone(), obj.icon_id())}; + obj.obsess_over_host(), obj.timezone(), obj.icon_id()); engine::host::hosts.insert({h->name(), h}); engine::host::hosts_by_id.insert({obj.host_id(), h}); diff --git a/engine/src/configuration/applier/hostescalation.cc b/engine/src/configuration/applier/hostescalation.cc index 564b692541f..8ed4aef8c7d 100644 --- a/engine/src/configuration/applier/hostescalation.cc +++ b/engine/src/configuration/applier/hostescalation.cc @@ -60,7 +60,7 @@ void applier::hostescalation::add_object( config->hostescalations().insert(obj); // Create host escalation. - std::shared_ptr he{new engine::hostescalation( + auto he = std::make_shared( *obj.hosts().begin(), obj.first_notification(), obj.last_notification(), obj.notification_interval(), obj.escalation_period(), ((obj.escalation_options() & configuration::hostescalation::down) @@ -73,7 +73,7 @@ void applier::hostescalation::add_object( ((obj.escalation_options() & configuration::hostescalation::recovery) ? notifier::up : notifier::none), - obj.uuid())}; + obj.uuid()); // Add new items to the configuration state. engine::hostescalation::hostescalations.insert({he->get_hostname(), he}); diff --git a/engine/src/configuration/applier/hostgroup.cc b/engine/src/configuration/applier/hostgroup.cc index d425a02ced0..3bede9295c8 100644 --- a/engine/src/configuration/applier/hostgroup.cc +++ b/engine/src/configuration/applier/hostgroup.cc @@ -64,9 +64,9 @@ void applier::hostgroup::add_object(configuration::hostgroup const& obj) { config->hostgroups().insert(obj); // Create host group. - std::shared_ptr hg{new engine::hostgroup( + auto hg = std::make_shared( obj.hostgroup_id(), obj.hostgroup_name(), obj.alias(), obj.notes(), - obj.notes_url(), obj.action_url())}; + obj.notes_url(), obj.action_url()); // Add new items to the configuration state. engine::hostgroup::hostgroups.insert({hg->get_group_name(), hg}); diff --git a/engine/src/configuration/applier/serviceescalation.cc b/engine/src/configuration/applier/serviceescalation.cc index 25b2ee61de5..e7eb32325cc 100644 --- a/engine/src/configuration/applier/serviceescalation.cc +++ b/engine/src/configuration/applier/serviceescalation.cc @@ -64,7 +64,7 @@ void applier::serviceescalation::add_object( config->serviceescalations().insert(obj); // Create service escalation. - std::shared_ptr se{new engine::serviceescalation( + auto se = std::make_shared( obj.hosts().front(), obj.service_description().front(), obj.first_notification(), obj.last_notification(), obj.notification_interval(), obj.escalation_period(), @@ -83,7 +83,7 @@ void applier::serviceescalation::add_object( configuration::serviceescalation::recovery) ? notifier::ok : notifier::none), - obj.uuid())}; + obj.uuid()); // Add new items to the global list. engine::serviceescalation::serviceescalations.insert( diff --git a/engine/src/configuration/applier/servicegroup.cc b/engine/src/configuration/applier/servicegroup.cc index d2ea1d162d5..c594a4505e2 100644 --- a/engine/src/configuration/applier/servicegroup.cc +++ b/engine/src/configuration/applier/servicegroup.cc @@ -77,9 +77,9 @@ void applier::servicegroup::add_object(configuration::servicegroup const& obj) { config->servicegroups().insert(obj); // Create servicegroup. - std::shared_ptr sg{new engine::servicegroup( + auto sg = std::make_shared( obj.servicegroup_id(), obj.servicegroup_name(), obj.alias(), obj.notes(), - obj.notes_url(), obj.action_url())}; + obj.notes_url(), obj.action_url()); // Add new items to the list. engine::servicegroup::servicegroups.insert({sg->get_group_name(), sg}); diff --git a/engine/src/configuration/applier/timeperiod.cc b/engine/src/configuration/applier/timeperiod.cc index 5e222b12e6b..3a4c55076cd 100644 --- a/engine/src/configuration/applier/timeperiod.cc +++ b/engine/src/configuration/applier/timeperiod.cc @@ -74,8 +74,8 @@ void applier::timeperiod::add_object(configuration::timeperiod const& obj) { config->timeperiods().insert(obj); // Create time period. - std::shared_ptr tp{ - new engine::timeperiod(obj.timeperiod_name(), obj.alias())}; + auto tp = + std::make_shared(obj.timeperiod_name(), obj.alias()); engine::timeperiod::timeperiods.insert({obj.timeperiod_name(), tp}); diff --git a/engine/src/configuration/object.cc b/engine/src/configuration/object.cc index 1933523d331..76fd084e27f 100644 --- a/engine/src/configuration/object.cc +++ b/engine/src/configuration/object.cc @@ -125,41 +125,41 @@ bool object::operator!=(object const& right) const noexcept { object_ptr object::create(std::string const& type_name) { object_ptr obj; if (type_name == "service") - obj = object_ptr(new configuration::service()); + obj = std::make_shared(); else if (type_name == "host") - obj = object_ptr(new configuration::host()); + obj = std::make_shared(); else if (type_name == "contact") - obj = object_ptr(new configuration::contact()); + obj = std::make_shared(); else if (type_name == "contactgroup") - obj = object_ptr(new configuration::contactgroup()); + obj = std::make_shared(); else if (type_name == "servicegroup") - obj = object_ptr(new configuration::servicegroup()); + obj = std::make_shared(); else if (type_name == "hostgroup") - obj = object_ptr(new configuration::hostgroup()); + obj = std::make_shared(); else if (type_name == "servicedependency") - obj = object_ptr(new configuration::servicedependency()); + obj = std::make_shared(); else if (type_name == "serviceescalation") - obj = object_ptr(new configuration::serviceescalation()); + obj = std::make_shared(); else if (type_name == "hostdependency") - obj = object_ptr(new configuration::hostdependency()); + obj = std::make_shared(); else if (type_name == "hostescalation") - obj = object_ptr(new configuration::hostescalation()); + obj = std::make_shared(); else if (type_name == "command") - obj = object_ptr(new configuration::command()); + obj = std::make_shared(); else if (type_name == "timeperiod") - obj = object_ptr(new configuration::timeperiod()); + obj = std::make_shared(); else if (type_name == "connector") - obj = object_ptr(new configuration::connector()); + obj = std::make_shared(); else if (type_name == "serviceextinfo") - obj = object_ptr(new configuration::serviceextinfo()); + obj = std::make_shared(); else if (type_name == "hostextinfo") - obj = object_ptr(new configuration::hostextinfo()); + obj = std::make_shared(); else if (type_name == "anomalydetection") - obj = object_ptr(new configuration::anomalydetection()); + obj = std::make_shared(); else if (type_name == "severity") - obj = object_ptr(new configuration::severity()); + obj = std::make_shared(); else if (type_name == "tag") - obj = object_ptr(new configuration::tag()); + obj = std::make_shared(); return obj; } diff --git a/engine/src/contact.cc b/engine/src/contact.cc index 4ee1f6810ee..5d28319a00b 100644 --- a/engine/src/contact.cc +++ b/engine/src/contact.cc @@ -548,7 +548,7 @@ std::shared_ptr add_contact( } // Allocate memory for a new contact. - std::shared_ptr obj(new contact); + auto obj = std::make_shared(); try { // Duplicate vars. diff --git a/engine/src/downtimes/host_downtime.cc b/engine/src/downtimes/host_downtime.cc index 077950bf923..61023356246 100644 --- a/engine/src/downtimes/host_downtime.cc +++ b/engine/src/downtimes/host_downtime.cc @@ -267,10 +267,10 @@ int host_downtime::subscribe() { /* add a non-persistent comment to the host or service regarding the scheduled * outage */ - std::shared_ptr com{ - new comment(comment::host, comment::downtime, hst->get_host_id(), 0, - time(NULL), "(Centreon Engine Process)", oss.str(), false, - comment::internal, false, (time_t)0)}; + auto com = std::make_shared( + comment::host, comment::downtime, hst->get_host_id(), 0, time(NULL), + "(Centreon Engine Process)", oss.str(), false, comment::internal, false, + (time_t)0); comment::comments.insert({com->get_comment_id(), com}); _comment_id = com->get_comment_id(); diff --git a/engine/src/events/loop.cc b/engine/src/events/loop.cc index 22c28728193..014a9e108f3 100644 --- a/engine/src/events/loop.cc +++ b/engine/src/events/loop.cc @@ -332,9 +332,10 @@ void loop::_dispatching() { else { if (notifier::soft == temp_service->get_state_type() && temp_service->get_current_state() != service::state_ok) - temp_service->set_next_check((time_t)( - temp_service->get_next_check() + - temp_service->retry_interval() * config->interval_length())); + temp_service->set_next_check( + (time_t)(temp_service->get_next_check() + + temp_service->retry_interval() * + config->interval_length())); else temp_service->set_next_check( (time_t)(temp_service->get_next_check() + diff --git a/engine/src/host.cc b/engine/src/host.cc index 5f7f072e1f5..d27d804e841 100644 --- a/engine/src/host.cc +++ b/engine/src/host.cc @@ -1791,10 +1791,10 @@ int host::run_async_check(int check_options, std::unique_ptr check_result_info; do { // Init check result info. - check_result_info.reset( - new check_result(host_check, this, checkable::check_active, - check_options, reschedule_check, latency, start_time, - start_time, false, true, service::state_ok, "")); + check_result_info = std::make_unique( + host_check, this, checkable::check_active, check_options, + reschedule_check, latency, start_time, start_time, false, true, + service::state_ok, ""); retry = false; try { @@ -2175,10 +2175,10 @@ void host::set_flap(double percent_change, << "% threshold). When the host state stabilizes and the " << "flapping stops, notifications will be re-enabled."; - std::shared_ptr com{ - new comment(comment::host, comment::flapping, get_host_id(), 0, - time(nullptr), "(Centreon Engine Process)", oss.str(), false, - comment::internal, false, (time_t)0)}; + auto com = std::make_shared( + comment::host, comment::flapping, get_host_id(), 0, time(nullptr), + "(Centreon Engine Process)", oss.str(), false, comment::internal, false, + (time_t)0); comment::comments.insert({com->get_comment_id(), com}); diff --git a/engine/src/notifier.cc b/engine/src/notifier.cc index 396d24ffb5b..24a061cec4b 100644 --- a/engine/src/notifier.cc +++ b/engine/src/notifier.cc @@ -946,9 +946,9 @@ int notifier::notify(notifier::reason_type type, get_contacts_to_notify(cat, type, notification_interval, escalated)}; _current_notification_id = _next_notification_id++; - std::unique_ptr notif{new notification( + auto notif = std::make_unique( this, type, not_author, not_data, options, _current_notification_id, - _notification_number, notification_interval, escalated)}; + _notification_number, notification_interval, escalated); /* Let's make the notification. */ int retval{notif->execute(to_notify)}; @@ -1782,10 +1782,9 @@ void notifier::set_notification(int32_t idx, std::string const& value) { } } } - - _notification[idx].reset(new notification(this, type, author, "", options, id, - number, interval, escalated, - contacts)); + _notification[idx] = + std::make_unique(this, type, author, "", options, id, + number, interval, escalated, contacts); } bool notifier::get_is_volatile() const noexcept { diff --git a/engine/src/retention/object.cc b/engine/src/retention/object.cc index 792b68e89eb..76e8a283bae 100644 --- a/engine/src/retention/object.cc +++ b/engine/src/retention/object.cc @@ -94,23 +94,23 @@ bool retention::object::operator!=(object const& right) const throw() { retention::object_ptr retention::object::create(std::string const& type_name) { object_ptr obj; if (type_name == "service") - obj = object_ptr(new retention::service); + obj = std::make_shared(); else if (type_name == "host") - obj = object_ptr(new retention::host); + obj = std::make_shared(); else if (type_name == "contact") - obj = object_ptr(new retention::contact); + obj = std::make_shared(); else if (type_name == "hostcomment") - obj = object_ptr(new retention::comment(comment::host)); + obj = std::make_shared(comment::host); else if (type_name == "servicecomment") - obj = object_ptr(new retention::comment(comment::service)); + obj = std::make_shared(comment::service); else if (type_name == "hostdowntime") - obj = object_ptr(new retention::downtime(downtime::host)); + obj = std::make_shared(downtime::host); else if (type_name == "servicedowntime") - obj = object_ptr(new retention::downtime(downtime::service)); + obj = std::make_shared(downtime::service); else if (type_name == "info") - obj = object_ptr(new retention::info); + obj = std::make_shared(); else if (type_name == "program") - obj = object_ptr(new retention::program); + obj = std::make_shared(); return obj; }