Commit 7bf32334 authored by Axel Auweter's avatar Axel Auweter
Browse files

Fix memory leaks in dcdbquery & compiler error.

parent 52e98234
......@@ -86,6 +86,8 @@ void DCDBQuery::lookupPublishedSensorPattern(CassSession* session, std::string n
statement = cass_prepared_bind(prepared);
cass_statement_bind_string_by_name(statement, "name", cass_string_init(name.c_str()));
cass_future_free(future);
future = cass_session_execute(session, statement);
cass_future_wait(future);
......@@ -109,6 +111,9 @@ void DCDBQuery::lookupPublishedSensorPattern(CassSession* session, std::string n
cass_result_free(result);
cass_iterator_free(iterator);
}
cass_future_free(future);
cass_statement_free(statement);
cass_prepared_free(prepared);
}
void DCDBQuery::expandSensorPattern(CassSession* session, std::string sensorPattern, DCDBTimeStamp start, DCDBTimeStamp end, std::list<SensorId>& sensorIds)
......@@ -171,6 +176,8 @@ void DCDBQuery::expandSensorPattern(CassSession* session, std::string sensorPatt
cass_statement_bind_bytes(statement, 0, lowCb);
cass_statement_bind_bytes(statement, 1, highCb);
cass_future_free(future);
future = cass_session_execute(session, statement);
cass_future_wait(future);
......@@ -299,9 +306,15 @@ void DCDBQuery::querySensorsCSV(CassSession* session, std::string sensorName, st
query << ";";
CassString csQuery = cass_string_init(query.str().c_str());
// HACK = sometimes the query fails for unknown reasons
int retries_left = 10;
while (retries_left) {
CassStatement* statement = cass_statement_new(csQuery, 0);
CassFuture* future = cass_session_execute(session, statement);
cass_future_wait(future);
if (cass_future_error_code(future) == CASS_OK) {
const CassResult* result = cass_future_get_result(future);
CassIterator* rows = cass_iterator_from_result(result);
......@@ -324,7 +337,22 @@ void DCDBQuery::querySensorsCSV(CassSession* session, std::string sensorName, st
std::cout << sensorName << "," << t.getString() << "," << std::dec << value << std::endl;
}
}
cass_iterator_free(rows);
cass_statement_free(statement);
cass_future_free(future);
break;
}
else {
retries_left--;
sleep(1);
// CassString message = cass_future_error_message(future);
// fprintf(stderr, "Error: %.*s\n", (int)message.length, message.data);
}
cass_statement_free(statement);
cass_future_free(future);
}
if (retries_left == 0) {
fprintf(stderr, "Error reading data. Please try again later.\n");
}
}
Supports Markdown
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