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. */
PathList &paths = node.Paths();
for (PathList::iterator i = paths.begin(); i != paths.end(); ++i) {
delete *i;
}
paths.clear();
node.Paths().clear();
}
job.path_allocator.ResetArena();
}

View File

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

View File

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