From 3ea67d36458ac907e24fc144fc0609e7fa0536c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Czern=C3=BD?= Date: Tue, 15 Sep 2020 11:16:00 +0200 Subject: [PATCH] F #4936: Reduce number of new/delete, use unique_ptr (#212) * On exit stop RequestManager first * Use unique_ptr for pointers to Template * Reduce number of new/delete --- include/Attribute.h | 22 +-- include/Cluster.h | 7 +- include/Datastore.h | 6 +- include/DatastorePool.h | 2 +- include/Document.h | 11 +- include/DocumentPool.h | 5 +- include/ExtendedAttribute.h | 2 +- include/Group.h | 4 +- include/Hook.h | 6 +- include/HookPool.h | 2 +- include/Host.h | 4 +- include/Image.h | 10 +- include/ImagePool.h | 2 +- include/ImageTemplate.h | 2 +- include/MarketPlace.h | 6 +- include/MarketPlaceApp.h | 6 +- include/MarketPlaceAppPool.h | 2 +- include/MarketPlacePool.h | 2 +- include/PoolObjectSQL.h | 9 +- include/RaftManager.h | 10 +- include/RequestManagerAllocate.h | 100 ++++++------ include/RequestManagerClone.h | 55 ++++--- include/SecurityGroup.h | 12 +- include/SecurityGroupPool.h | 2 +- include/User.h | 6 +- include/VMGroup.h | 6 +- include/VMGroupPool.h | 3 +- include/VMTemplate.h | 13 +- include/VMTemplatePool.h | 2 +- include/VNTemplate.h | 13 +- include/VNTemplatePool.h | 2 +- include/Vdc.h | 6 +- include/VdcPool.h | 2 +- include/VirtualMachine.h | 21 ++- include/VirtualMachineDisk.h | 2 +- include/VirtualMachinePool.h | 2 +- include/VirtualMachineTemplate.h | 2 +- include/VirtualNetwork.h | 15 +- include/VirtualNetworkPool.h | 2 +- include/VirtualNetworkTemplate.h | 2 +- include/VirtualRouter.h | 12 +- include/VirtualRouterPool.h | 4 +- include/Zone.h | 6 +- include/ZonePool.h | 2 +- src/acl/AclManager.cc | 2 +- src/cluster/Cluster.cc | 8 +- src/common/Attribute.cc | 9 +- src/datastore/Datastore.cc | 8 +- src/datastore/DatastorePool.cc | 17 +- src/dm/DispatchManagerActions.cc | 8 +- src/document/Document.cc | 8 +- src/group/Group.cc | 2 +- src/hm/Hook.cc | 16 +- src/hm/HookPool.cc | 4 +- src/host/Host.cc | 2 +- src/image/Image.cc | 13 +- src/image/ImagePool.cc | 4 +- src/market/MarketPlace.cc | 8 +- src/market/MarketPlaceApp.cc | 10 +- src/market/MarketPlaceAppPool.cc | 4 +- src/market/MarketPlacePool.cc | 20 +-- src/monitor/include/HostMonitorManager.h | 10 +- src/monitor/include/VirtualMachineBase.h | 10 +- .../src/data_model/VirtualMachineBase.cc | 4 +- src/monitor/src/monitor/HostMonitorManager.cc | 12 +- src/monitor/src/monitor/Monitor.cc | 22 +-- .../src/monitor/MonitorDriverProtocol.cc | 2 +- src/nebula/Nebula.cc | 3 +- src/pool/PoolObjectSQL.cc | 60 +++---- src/raft/RaftManager.cc | 16 +- src/rm/RequestManagerAllocate.cc | 153 ++++++++---------- src/rm/RequestManagerChown.cc | 58 +++---- src/rm/RequestManagerClone.cc | 8 +- src/rm/RequestManagerImage.cc | 14 +- src/rm/RequestManagerInfo.cc | 11 +- src/rm/RequestManagerVMTemplate.cc | 48 ++---- src/rm/RequestManagerVNTemplate.cc | 11 +- src/rm/RequestManagerVirtualMachine.cc | 17 +- src/rm/RequestManagerVirtualNetwork.cc | 6 +- src/scheduler/include/VirtualMachineXML.h | 20 +-- src/scheduler/src/pool/VirtualMachineXML.cc | 21 ++- src/scheduler/src/sched/Scheduler.cc | 8 +- src/secgroup/SecurityGroup.cc | 8 +- src/secgroup/SecurityGroupPool.cc | 13 +- src/template/Template.cc | 23 +-- src/um/Quota.cc | 6 +- src/vdc/Vdc.cc | 8 +- src/vdc/VdcPool.cc | 10 +- src/vm/VirtualMachine.cc | 117 ++++++-------- src/vm/VirtualMachineContext.cc | 19 +-- src/vm/VirtualMachineDisk.cc | 6 +- src/vm/VirtualMachineParser.cc | 12 +- src/vm/VirtualMachinePool.cc | 6 +- src/vm_group/VMGroup.cc | 8 +- src/vm_group/VMGroupPool.cc | 6 +- src/vm_template/VMTemplate.cc | 16 +- src/vm_template/VMTemplatePool.cc | 9 +- src/vn_template/VNTemplate.cc | 11 +- src/vn_template/VNTemplatePool.cc | 9 +- src/vnm/VirtualNetwork.cc | 11 +- src/vnm/VirtualNetworkPool.cc | 10 +- src/vrouter/VirtualRouter.cc | 27 ++-- src/zone/Zone.cc | 8 +- src/zone/ZonePool.cc | 9 +- 104 files changed, 619 insertions(+), 802 deletions(-) diff --git a/include/Attribute.h b/include/Attribute.h index 47438322d0..7884b86420 100644 --- a/include/Attribute.h +++ b/include/Attribute.h @@ -70,11 +70,10 @@ public: }; /** - * Marshall the attribute in a single string. The string MUST be freed - * by the calling function. - * @return a string (allocated in the heap) holding the attribute value. + * Marshall the attribute in a single string. + * @return a string holding the attribute value. */ - virtual std::string * marshall(const char * _sep = 0) const = 0; + virtual std::string marshall(const char * _sep = 0) const = 0; /** * Write the attribute using a simple XML format. The string MUST be freed @@ -153,17 +152,12 @@ public: }; /** - * Marshall the attribute in a single string. The string MUST be freed - * by the calling function. - * @return a string (allocated in the heap) holding the attribute value. + * Marshall the attribute in a single string. + * @return a string holding the attribute value. */ - std::string * marshall(const char * _sep = 0) const override + std::string marshall(const char * _sep = 0) const override { - auto rs = new std::string; - - *rs = attribute_value; - - return rs; + return attribute_value; }; /** @@ -391,7 +385,7 @@ public: * "VAL_NAME_1=VAL_VALUE_1,...,VAL_NAME_N=VAL_VALUE_N". * @return a string (allocated in the heap) holding the attribute value. */ - std::string * marshall(const char * _sep = 0) const override; + std::string marshall(const char * _sep = 0) const override; /** * Write the attribute using a simple XML format: diff --git a/include/Cluster.h b/include/Cluster.h index 128884ab27..4abbeca745 100644 --- a/include/Cluster.h +++ b/include/Cluster.h @@ -138,7 +138,8 @@ private: // ************************************************************************* // Constructor // ************************************************************************* - Cluster(int id, const std::string& name, ClusterTemplate* cl_template, + Cluster(int id, const std::string& name, + std::unique_ptr cl_template, const VectorAttribute& vnc_conf); // ************************************************************************* @@ -256,9 +257,9 @@ private: /** * Factory method for cluster templates */ - Template * get_new_template() const override + std::unique_ptr