From d27b19ce084e22d027b3a32182f54339285ad67a Mon Sep 17 00:00:00 2001 From: Eugenio Collado Date: Tue, 31 Dec 2024 15:18:56 +0100 Subject: [PATCH] ASAN fix Signed-off-by: Eugenio Collado --- .../test/blackbox/sql/SqlFileCreationTest.cpp | 51 ++++++++++--------- .../cpp/replayer/BaseReaderParticipant.cpp | 1 + 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/ddsrecorder/test/blackbox/sql/SqlFileCreationTest.cpp b/ddsrecorder/test/blackbox/sql/SqlFileCreationTest.cpp index ce6c2294..f50b50e2 100644 --- a/ddsrecorder/test/blackbox/sql/SqlFileCreationTest.cpp +++ b/ddsrecorder/test/blackbox/sql/SqlFileCreationTest.cpp @@ -91,39 +91,42 @@ class SqlFileCreationTest : public FileCreationTest throw std::runtime_error(error_msg); } - // Guard the statement to ensure it's always finalized - std::unique_ptr stmt_guard(stmt, sqlite3_finalize); - - // Bind the values to the statement - for (int i = 0; i < (int) bind_values.size(); i++) { - const auto bind_ret = sqlite3_bind_text(stmt, i+1, bind_values[i].c_str(), -1, SQLITE_STATIC); - if (bind_ret != SQLITE_OK) + // Guard the statement to ensure it's always finalized + std::unique_ptr stmt_guard(stmt, sqlite3_finalize); + + // Bind the values to the statement + for (int i = 0; i < (int) bind_values.size(); i++) { - const std::string error_msg = utils::Formatter() << "Failed to bind SQL statement to read messages: " - << sqlite3_errmsg(database); + const auto bind_ret = sqlite3_bind_text(stmt, i+1, bind_values[i].c_str(), -1, SQLITE_STATIC); - logError(DDSREPLAYER_SQL_READER_PARTICIPANT, "FAIL_SQL_READ | " << error_msg); - throw std::runtime_error(error_msg); + if (bind_ret != SQLITE_OK) + { + const std::string error_msg = utils::Formatter() << "Failed to bind SQL statement to read messages: " + << sqlite3_errmsg(database); + + logError(DDSREPLAYER_SQL_READER_PARTICIPANT, "FAIL_SQL_READ | " << error_msg); + throw std::runtime_error(error_msg); + } } - } - // Step through the statement and process the rows - int step_ret; + // Step through the statement and process the rows + int step_ret; - while ((step_ret = sqlite3_step(stmt)) == SQLITE_ROW) - { - process_row(stmt); - } + while ((step_ret = sqlite3_step(stmt)) == SQLITE_ROW) + { + process_row(stmt); + } - if (step_ret != SQLITE_DONE) - { - const std::string error_msg = utils::Formatter() << "Failed to fetch data: " - << sqlite3_errmsg(database); + if (step_ret != SQLITE_DONE) + { + const std::string error_msg = utils::Formatter() << "Failed to fetch data: " + << sqlite3_errmsg(database); - logError(DDSREPLAYER_SQL_READER_PARTICIPANT, "FAIL_SQL_READ | " << error_msg); - throw std::runtime_error(error_msg); + logError(DDSREPLAYER_SQL_READER_PARTICIPANT, "FAIL_SQL_READ | " << error_msg); + throw std::runtime_error(error_msg); + } } // Close the database diff --git a/ddsrecorder_participants/src/cpp/replayer/BaseReaderParticipant.cpp b/ddsrecorder_participants/src/cpp/replayer/BaseReaderParticipant.cpp index 66f94e73..b7b2d422 100644 --- a/ddsrecorder_participants/src/cpp/replayer/BaseReaderParticipant.cpp +++ b/ddsrecorder_participants/src/cpp/replayer/BaseReaderParticipant.cpp @@ -113,6 +113,7 @@ std::unique_ptr BaseReaderParticipant::cr ddspipe::core::types::Payload payload(raw_data_size); payload.max_size = raw_data_size; payload.length = raw_data_size; + free(payload.data); payload.data = (unsigned char*) reinterpret_cast(raw_data); // Reserve and copy the payload into the payload pool