Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
plug a memleak
[simgrid.git] / src / surf / VirtualMachineImpl.cpp
index 624465e..8ad7f58 100644 (file)
@@ -4,7 +4,8 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "VirtualMachineImpl.hpp"
+#include "src/surf/VirtualMachineImpl.hpp"
+#include "simgrid/s4u/VirtualMachine.hpp"
 
 #include <xbt/signal.hpp>
 
@@ -39,12 +40,6 @@ simgrid::xbt::signal<void(simgrid::surf::VirtualMachineImpl*)> onVmStateChange;
 
 std::deque<VirtualMachineImpl*> VirtualMachineImpl::allVms_;
 
-s4u::Host* VMModel::createVM(const char* name, sg_host_t host_PM)
-{
-  VirtualMachineImpl* vm = new VirtualMachineImpl(name, host_PM);
-  return vm->piface_;
-}
-
 /* In the real world, processes on the guest operating system will be somewhat degraded due to virtualization overhead.
  * The total CPU share these processes get is smaller than that of the VM process gets on a host operating system. */
 // const double virt_overhead = 0.95;
@@ -103,8 +98,8 @@ double VMModel::nextOccuringEvent(double now)
  * Resource *
  ************/
 
-VirtualMachineImpl::VirtualMachineImpl(const char* name, simgrid::s4u::Host* host_PM)
-    : HostImpl(new simgrid::s4u::Host(name), nullptr /*storage*/), hostPM_(host_PM)
+VirtualMachineImpl::VirtualMachineImpl(simgrid::s4u::Host* piface, simgrid::s4u::Host* host_PM)
+    : HostImpl(piface, nullptr /*storage*/), hostPM_(host_PM)
 {
   /* Register this VM to the list of all VMs */
   allVms_.push_back(this);
@@ -129,7 +124,8 @@ VirtualMachineImpl::VirtualMachineImpl(const char* name, simgrid::s4u::Host* hos
   /* FIXME: TODO: we have to periodically input GUESTOS_NOISE to the system? how ? */
   action_ = sub_cpu->execution_start(0);
 
-  XBT_VERB("Create VM(%s)@PM(%s) with %ld mounted disks", name, hostPM_->name().c_str(), xbt_dynar_length(storage_));
+  XBT_VERB("Create VM(%s)@PM(%s) with %ld mounted disks", piface->name().c_str(), hostPM_->name().c_str(),
+           xbt_dynar_length(storage_));
 }
 
 /*
@@ -143,6 +139,8 @@ VirtualMachineImpl::~VirtualMachineImpl()
   /* Free the cpu_action of the VM. */
   XBT_ATTRIB_UNUSED int ret = action_->unref();
   xbt_assert(ret == 1, "Bug: some resource still remains");
+
+  delete piface_->pimpl_cpu;
 }
 
 e_surf_vm_state_t VirtualMachineImpl::getState()
@@ -181,13 +179,13 @@ void VirtualMachineImpl::restore()
 }
 
 /** @brief returns the physical machine on which the VM is running **/
-sg_host_t VirtualMachineImpl::getPm()
+s4u::Host* VirtualMachineImpl::getPm()
 {
   return hostPM_;
 }
 
 /* Update the physical host of the given VM */
-void VirtualMachineImpl::migrate(sg_host_t host_dest)
+void VirtualMachineImpl::migrate(s4u::Host* host_dest)
 {
   const char* vm_name     = piface_->name().c_str();
   const char* pm_name_src = hostPM_->name().c_str();