Skip to content

Commit ea19516

Browse files
authored
Feature/cppclient asan (#16293)
* implement client-cpp memory check(asan) * fix ubuntu compilation * fix compilation error * fix memory leak * fix conpilation error on moacos
1 parent 484bc09 commit ea19516

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

iotdb-client/client-cpp/src/main/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ ELSE()
4141
SET(THRIFT_STATIC_LIB "${CMAKE_SOURCE_DIR}/../../thrift/lib/libthrift.a")
4242
ENDIF()
4343

44+
IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND NOT MSVC)
45+
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
46+
add_link_options(-fsanitize=address)
47+
ENDIF()
48+
4449
# Add the generated source files to the sources for the library.
4550
AUX_SOURCE_DIRECTORY(./generated-sources-cpp SESSION_SRCS)
4651
IF(MSVC)

iotdb-client/client-cpp/src/test/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ ELSE()
4747
SET(THRIFT_STATIC_LIB "${CMAKE_SOURCE_DIR}/../../thrift/lib/libthrift.a")
4848
ENDIF()
4949

50+
IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND NOT MSVC)
51+
add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
52+
add_link_options(-fsanitize=address)
53+
ENDIF()
54+
5055
ADD_EXECUTABLE(${TARGET_NAME} main.cpp cpp/sessionIT.cpp)
5156
ADD_EXECUTABLE(${TARGET_NAME_RELATIONAL} main_Relational.cpp cpp/sessionRelationalIT.cpp)
5257

iotdb-client/client-cpp/src/test/cpp/sessionIT.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ TEST_CASE("Test insertRecord by string", "[testInsertRecord]") {
141141
while (sessionDataSet->hasNext()) {
142142
long index = 1;
143143
count++;
144-
for (const Field &f: sessionDataSet->next()->fields) {
144+
auto fields = sessionDataSet->next()->fields;
145+
for (const Field &f: fields) {
145146
REQUIRE(f.longV.value() == index);
146147
index++;
147148
}
@@ -186,7 +187,8 @@ TEST_CASE("Test insertRecords ", "[testInsertRecords]") {
186187
while (sessionDataSet->hasNext()) {
187188
long index = 1;
188189
count++;
189-
for (const Field &f: sessionDataSet->next()->fields) {
190+
auto fields = sessionDataSet->next()->fields;
191+
for (const Field &f: fields) {
190192
REQUIRE(f.longV.value() == index);
191193
index++;
192194
}
@@ -386,7 +388,8 @@ TEST_CASE("Test insertTablet ", "[testInsertTablet]") {
386388
while (sessionDataSet->hasNext()) {
387389
long index = 0;
388390
count++;
389-
for (const Field& f: sessionDataSet->next()->fields) {
391+
auto fields = sessionDataSet->next()->fields;
392+
for (const Field &f: fields) {
390393
REQUIRE(f.longV.value() == index);
391394
index++;
392395
}
@@ -436,7 +439,8 @@ TEST_CASE("Test insertTablets ", "[testInsertTablets]") {
436439
while (sessionDataSet->hasNext()) {
437440
long index = 0;
438441
count++;
439-
for (const Field& f: sessionDataSet->next()->fields) {
442+
auto fields = sessionDataSet->next()->fields;
443+
for (const Field &f: fields) {
440444
REQUIRE(f.longV.value() == index);
441445
index++;
442446
}
@@ -614,10 +618,6 @@ TEST_CASE("Test executeRawDataQuery ", "[executeRawDataQuery]") {
614618
sessionDataSet->setFetchSize(10);
615619
vector<string> columns = sessionDataSet->getColumnNames();
616620
columns = sessionDataSet->getColumnNames();
617-
for (const string &column : columns) {
618-
cout << column << " " ;
619-
}
620-
cout << endl;
621621
REQUIRE(columns[0] == "Time");
622622
REQUIRE(columns[1] == paths[0]);
623623
REQUIRE(columns[2] == paths[1]);

0 commit comments

Comments
 (0)