8000 Bug fix/fix collection leak by jsteemann · Pull Request #2986 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Bug fix/fix collection leak #2986

New issue
Merged
merged 3 commits into from
Aug 8, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
Next Next commit
fix a memleak in db._collections() on coordinator when there are no…
… access rights to a collection
  • Loading branch information
jsteemann committed Aug 8, 2017
commit 260a938ed2b23b6ee42582f08fce1f5d9c91263e
17 changes: 16 additions & 1 deletion arangod/V8Server/v8-collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3045,15 +3045,28 @@ static void JS_CollectionsVocbase(
}

std::vector<LogicalCollection*> colls;

// clean memory
std::function<void()> cleanup;

// if we are a coordinator, we need to fetch the collection info from the
// agency
if (ServerState::instance()->isCoordinator()) {
cleanup = [&colls]() {
for (auto& it : colls) {
if (it != nullptr) {
delete it;
}
}
};
colls = GetCollectionsCluster(vocbase);
} else {
colls = vocbase->collections(false);
}

// make sure memory is cleaned up
TRI_DEFER(cleanup());

std::sort(colls.begin(), colls.end(), [](LogicalCollection* lhs, LogicalCollection* rhs) -> bool {
return StringUtils::tolower(lhs->name()) < StringUtils::tolower(rhs->name());
});
Expand All @@ -3066,7 +3079,7 @@ static void JS_CollectionsVocbase(
size_t const n = colls.size();
size_t x = 0;
for (size_t i = 0; i < n; ++i) {
auto collection = colls[i];
auto& collection = colls[i];

if (auth->isActive() && ExecContext::CURRENT != nullptr) {
AuthLevel level = auth->canUseCollection(ExecContext::CURRENT->user(),
Expand All @@ -3081,6 +3094,8 @@ static void JS_CollectionsVocbase(
error = true;
break;
}
// avoid duplicate deletion
collection = nullptr;
result->Set(static_cast<uint32_t>(x++), c);
}

Expand Down
0