Linkgraph: Use an arena allocator for path objects.

Fixes leaks when job is aborted early.
This commit is contained in:
Jonathan G Rennison
2017-02-08 21:46:32 +00:00
parent a67ecb4f6e
commit c86a027e88
3 changed files with 11 additions and 8 deletions

View File

@@ -60,10 +60,7 @@ void FlowMapper::Run(LinkGraphJob &job) const
} }
} }
/* Clear paths. */ /* Clear paths. */
PathList &paths = node.Paths(); node.Paths().clear();
for (PathList::iterator i = paths.begin(); i != paths.end(); ++i) {
delete *i;
}
paths.clear();
} }
job.path_allocator.ResetArena();
} }

View File

@@ -13,6 +13,7 @@
#define LINKGRAPHJOB_H #define LINKGRAPHJOB_H
#include "../thread/thread.h" #include "../thread/thread.h"
#include "../core/dyn_arena_alloc.hpp"
#include "linkgraph.h" #include "linkgraph.h"
#include <list> #include <list>
#include <memory> #include <memory>
@@ -77,6 +78,8 @@ protected:
public: public:
DynUniformArenaAllocator path_allocator; ///< Arena allocator used for paths
bool IsJobAborted() const; bool IsJobAborted() const;
/** /**

View File

@@ -378,8 +378,11 @@ void MultiCommodityFlow::Dijkstra(NodeID source_node, PathVector &paths)
Tedge_iterator iter(this->job); Tedge_iterator iter(this->job);
uint size = this->job.Size(); uint size = this->job.Size();
paths.resize(size, NULL); paths.resize(size, NULL);
this->job.path_allocator.SetParameters(sizeof(AnnosWrapper<Tannotation>), (8192 - 32) / sizeof(AnnosWrapper<Tannotation>));
for (NodeID node = 0; node < size; ++node) { for (NodeID node = 0; node < size; ++node) {
AnnosWrapper<Tannotation> *anno = new AnnosWrapper<Tannotation>(node, node == source_node); AnnosWrapper<Tannotation> *anno = new (this->job.path_allocator.Allocate()) AnnosWrapper<Tannotation>(node, node == source_node);
anno->UpdateAnnotation(); anno->UpdateAnnotation();
anno->self_iter = annos.insert(AnnoSetItem<Tannotation>(anno)).first; anno->self_iter = annos.insert(AnnoSetItem<Tannotation>(anno)).first;
paths[node] = anno; paths[node] = anno;
@@ -431,12 +434,12 @@ void MultiCommodityFlow::CleanupPaths(NodeID source_id, PathVector &paths)
path->Detach(); path->Detach();
if (path->GetNumChildren() == 0) { if (path->GetNumChildren() == 0) {
paths[path->GetNode()] = NULL; paths[path->GetNode()] = NULL;
delete path; this->job.path_allocator.Free(path);
} }
path = parent; path = parent;
} }
} }
delete source; this->job.path_allocator.Free(source);
paths.clear(); paths.clear();
} }