16.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit a9e4962b authored by Michael Ott's avatar Michael Ott
Browse files

Fix segfaults due to erasing elements of the querries container in the inner loop

parent 41186ff3
......@@ -396,29 +396,34 @@ void DCDBQuery::prepareQuery(std::list<std::string> sensors, std::list<std::stri
void DCDBQuery::execute() {
std::string prevSensorName;
for (auto q: queries) {
if (q.first.name != prevSensorName) {
auto q = queries.begin();
while (q != queries.end()) {
if (q->first.name != prevSensorName) {
// Find all queries for the same sensor
std::pair<queryMap_t::iterator, queryMap_t::iterator> range = queries.equal_range(q.first);
std::pair<queryMap_t::iterator, queryMap_t::iterator> range = queries.equal_range(q->first);
/* Base scaling factor and unit of the public sensor */
baseUnit = DCDB::UnitConv::fromString(q.first.unit);
baseScalingFactor = q.first.scaling_factor;
baseUnit = DCDB::UnitConv::fromString(q->first.unit);
baseScalingFactor = q->first.scaling_factor;
std::list<DCDB::SensorDataStoreReading> results;
DCDB::Sensor sensor(connection, q.first);
DCDB::Sensor sensor(connection, q->first);
// Query aggregates first
auto it=range.first;
while(it!=range.second) {
while(it!=range.second) {
if (it->second.aggregate != DCDB::AGGREGATE_NONE) {
sensor.query(results, start_ts, end_ts, it->second.aggregate);
if (results.size() > 0) {
genOutput(results, it, std::next(it));
results.clear();
// Remove the query from the list so it doesn't show up in the raw values below anymore
if (it == range.first) {
range.first = std::next(it);
}
if (it == q) {
q = std::next(q);
}
it = queries.erase(it);
continue;
}
......@@ -427,7 +432,7 @@ void DCDBQuery::execute() {
}
// Query raw values next
for (auto it=range.first; it!=range.second; it++) {
for (auto it=range.first; it!=range.second; it++) {
if (it->second.aggregate == DCDB::AGGREGATE_NONE) {
sensor.query(results, start_ts, end_ts, DCDB::AGGREGATE_NONE);
break;
......@@ -439,8 +444,9 @@ void DCDBQuery::execute() {
}
prevSensorName = q.first.name;
prevSensorName = q->first.name;
}
q++;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment