1
0
Fork 0

fixed segfault

This commit is contained in:
Jan Steemann 2016-01-12 10:49:43 +01:00
parent e4992ff37a
commit 88d49eaef1
4 changed files with 20 additions and 41 deletions

View File

@ -39,7 +39,7 @@ namespace arango {
namespace aql {
struct Aggregator {
Aggregator(triagens::arango::AqlTransaction* trx) : trx(trx) { }
explicit Aggregator(triagens::arango::AqlTransaction* trx) : trx(trx) { }
virtual ~Aggregator() = default;
virtual char const* name() const = 0;
virtual void reset() = 0;
@ -56,7 +56,8 @@ struct Aggregator {
};
struct AggregatorLength final : public Aggregator {
AggregatorLength(triagens::arango::AqlTransaction* trx) : Aggregator(trx), count(0) { }
explicit AggregatorLength(triagens::arango::AqlTransaction* trx) : Aggregator(trx), count(0) { }
AggregatorLength(triagens::arango::AqlTransaction* trx, uint64_t initialCount) : Aggregator(trx), count(initialCount) { }
char const* name() const override final {
return "LENGTH";
@ -70,7 +71,7 @@ struct AggregatorLength final : public Aggregator {
};
struct AggregatorMin final : public Aggregator {
AggregatorMin(triagens::arango::AqlTransaction* trx) : Aggregator(trx), value(), coll(nullptr) { }
explicit AggregatorMin(triagens::arango::AqlTransaction* trx) : Aggregator(trx), value(), coll(nullptr) { }
~AggregatorMin();
@ -87,7 +88,7 @@ struct AggregatorMin final : public Aggregator {
};
struct AggregatorMax final : public Aggregator {
AggregatorMax(triagens::arango::AqlTransaction* trx) : Aggregator(trx), value(), coll(nullptr) { }
explicit AggregatorMax(triagens::arango::AqlTransaction* trx) : Aggregator(trx), value(), coll(nullptr) { }
~AggregatorMax();
@ -104,7 +105,7 @@ struct AggregatorMax final : public Aggregator {
};
struct AggregatorSum final : public Aggregator {
AggregatorSum(triagens::arango::AqlTransaction* trx) : Aggregator(trx), sum(0.0), invalid(false) { }
explicit AggregatorSum(triagens::arango::AqlTransaction* trx) : Aggregator(trx), sum(0.0), invalid(false) { }
~AggregatorSum();
@ -121,7 +122,7 @@ struct AggregatorSum final : public Aggregator {
};
struct AggregatorAverage final : public Aggregator {
AggregatorAverage(triagens::arango::AqlTransaction* trx) : Aggregator(trx), count(0), sum(0.0), invalid(false) { }
explicit AggregatorAverage(triagens::arango::AqlTransaction* trx) : Aggregator(trx), count(0), sum(0.0), invalid(false) { }
~AggregatorAverage();

View File

@ -330,25 +330,6 @@ bool AqlValue::isNull(bool emptyIsNull) const {
THROW_ARANGO_EXCEPTION(TRI_ERROR_INTERNAL);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief increase value for (numeric) AQL value
////////////////////////////////////////////////////////////////////////////////
void AqlValue::increase() {
if (_type == JSON) {
TRI_json_t* json = _json->json();
if (TRI_IsNumberJson(json)) {
double value = json->_value._number;
// overwrite existing number
TRI_InitNumberJson(json, value + 1.0);
return;
}
}
THROW_ARANGO_EXCEPTION(TRI_ERROR_INTERNAL);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the array member at position i
////////////////////////////////////////////////////////////////////////////////

View File

@ -219,12 +219,6 @@ struct AqlValue {
bool isNull(bool emptyIsNull) const;
////////////////////////////////////////////////////////////////////////////////
/// @brief increase value for (numeric) AQL value
////////////////////////////////////////////////////////////////////////////////
void increase();
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the array member at position i
//////////////////////////////////////////////////////////////////////////////

View File

@ -569,6 +569,8 @@ int HashedCollectBlock::getOrSkipSome(size_t atLeast, size_t atMost,
aggregateColls.emplace_back(cur->getDocumentCollection(it.second));
}
TRI_ASSERT(aggregateColls.size() == en->_aggregateVariables.size());
TRI_ASSERT(_aggregateRegisters.size() == en->_aggregateVariables.size());
typedef std::vector<Aggregator*> AggregateValuesType;
@ -583,6 +585,7 @@ int HashedCollectBlock::getOrSkipSome(size_t atLeast, size_t atMost,
}
delete it.second;
}
allGroups.clear();
};
// prevent memory leaks by always cleaning up the groups
@ -624,18 +627,17 @@ int HashedCollectBlock::getOrSkipSome(size_t atLeast, size_t atMost,
->erase(); // to prevent double-freeing later
}
size_t j = 0;
for (auto const& r : *(it.second)) {
// TODO: check if cloning is necessary
result->setValue(row, _aggregateRegisters[j++].first, r->stealValue());
if (it.second != nullptr && ! en->_count) {
TRI_ASSERT(it.second->size() == _aggregateRegisters.size());
size_t j = 0;
for (auto const& r : *(it.second)) {
result->setValue(row, _aggregateRegisters[j++].first, r->stealValue());
}
}
if (en->_count) {
else if (en->_count) {
// set group count in result register
// TODO: check if cloning is necessary
TRI_ASSERT(it.second != nullptr);
result->setValue(row, _collectRegister, it.second->back()->stealValue());
// int64_t value = (*(it.second))[0].toInt64();
//result->setValue(row, _collectRegister, AqlValue(new Json(static_cast<double>(value))));
}
++row;
@ -682,7 +684,7 @@ int HashedCollectBlock::getOrSkipSome(size_t atLeast, size_t atMost,
if (en->_aggregateVariables.empty()) {
// no aggregate registers. this means we'll only count the number of items
if (en->_count) {
aggregateValues->emplace_back(new AggregatorLength(_trx));
aggregateValues->emplace_back(new AggregatorLength(_trx, 1));
}
}
else {
@ -698,6 +700,7 @@ int HashedCollectBlock::getOrSkipSome(size_t atLeast, size_t atMost,
}
}
// note: aggregateValues may be a nullptr!
allGroups.emplace(group, aggregateValues.get());
aggregateValues.release();
} else {