Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Use std::unique_ptr for Process::heap
authorGabriel Corona <gabriel.corona@loria.fr>
Mon, 2 Nov 2015 10:11:37 +0000 (11:11 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Mon, 2 Nov 2015 10:11:37 +0000 (11:11 +0100)
src/mc/Process.cpp
src/mc/Process.hpp

index e644b4a..125c722 100644 (file)
@@ -216,7 +216,6 @@ Process::Process(pid_t pid, int sockfd) : AddressSpace(this)
   process->status_ = 0;
   process->memory_map_ = get_memory_map(pid);
   process->cache_flags = MC_PROCESS_CACHE_FLAG_NONE;
   process->status_ = 0;
   process->memory_map_ = get_memory_map(pid);
   process->cache_flags = MC_PROCESS_CACHE_FLAG_NONE;
-  process->heap = NULL;
   process->heap_info = NULL;
   process->init_memory_map_info();
   process->clear_refs_fd_ = -1;
   process->heap_info = NULL;
   process->init_memory_map_info();
   process->clear_refs_fd_ = -1;
@@ -275,9 +274,6 @@ Process::~Process()
 
   process->cache_flags = MC_PROCESS_CACHE_FLAG_NONE;
 
 
   process->cache_flags = MC_PROCESS_CACHE_FLAG_NONE;
 
-  free(process->heap);
-  process->heap = NULL;
-
   free(process->heap_info);
   process->heap_info = NULL;
 
   free(process->heap_info);
   process->heap_info = NULL;
 
@@ -296,11 +292,10 @@ void Process::refresh_heap()
 {
   xbt_assert(mc_mode == MC_MODE_SERVER);
   // Read/dereference/refresh the std_heap pointer:
 {
   xbt_assert(mc_mode == MC_MODE_SERVER);
   // Read/dereference/refresh the std_heap pointer:
-  if (!this->heap) {
-    this->heap = (struct mdesc*) malloc(sizeof(struct mdesc));
-  }
-  this->read_bytes(this->heap, sizeof(struct mdesc), remote(this->heap_address),
-    simgrid::mc::ProcessIndexDisabled);
+  if (!this->heap)
+    this->heap = std::unique_ptr<s_xbt_mheap_t>(new s_xbt_mheap_t());
+  this->read_bytes(this->heap.get(), sizeof(struct mdesc),
+    remote(this->heap_address), simgrid::mc::ProcessIndexDisabled);
   this->cache_flags |= MC_PROCESS_CACHE_FLAG_HEAP;
 }
 
   this->cache_flags |= MC_PROCESS_CACHE_FLAG_HEAP;
 }
 
index ff36fa1..f6b941a 100644 (file)
@@ -94,7 +94,7 @@ public:
   {
     if (!(this->cache_flags & MC_PROCESS_CACHE_FLAG_HEAP))
       this->refresh_heap();
   {
     if (!(this->cache_flags & MC_PROCESS_CACHE_FLAG_HEAP))
       this->refresh_heap();
-    return this->heap;
+    return this->heap.get();
   }
   malloc_info* get_malloc_info()
   {
   }
   malloc_info* get_malloc_info()
   {
@@ -200,7 +200,7 @@ public: // Copies of MCed SMX data structures
    *  This is not used if the process is the current one:
    *  use `get_heap_info()` in order to use it.
    */
    *  This is not used if the process is the current one:
    *  use `get_heap_info()` in order to use it.
    */
-   xbt_mheap_t heap;
+   std::unique_ptr<s_xbt_mheap_t> heap;
 
   /** Copy of the allocation info structure
    *
 
   /** Copy of the allocation info structure
    *