Skip to content

Commit fd4785f

Browse files
committed
ci: fix memory leak and enable sanitizer ci
1 parent 3cf5963 commit fd4785f

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

.github/workflows/sanitizer_test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ jobs:
5050
- name: Run Tests
5151
working-directory: build
5252
env:
53-
ASAN_OPTIONS: log_path=out.log:detect_leaks=1:symbolize=1:strict_string_checks=1:halt_on_error=0:detect_container_overflow=0
53+
ASAN_OPTIONS: log_path=out.log:detect_leaks=1:symbolize=1:strict_string_checks=1:halt_on_error=1:detect_container_overflow=0
5454
LSAN_OPTIONS: suppressions=${{ github.workspace }}/.github/lsan-suppressions.txt
55-
UBSAN_OPTIONS: log_path=out.log:halt_on_error=0:print_stacktrace=1:suppressions=${{ github.workspace }}/.github/ubsan-suppressions.txt
55+
UBSAN_OPTIONS: log_path=out.log:halt_on_error=1:print_stacktrace=1:suppressions=${{ github.workspace }}/.github/ubsan-suppressions.txt
5656
run: |
5757
ctest --output-on-failure
5858
- name: Save the test output

test/arrow_test.cc

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@
3535

3636
namespace iceberg {
3737

38+
namespace {
39+
40+
// A RAII guard for ArrowSchema.
41+
struct ArrowSchemaGuard {
42+
ArrowSchema* schema;
43+
~ArrowSchemaGuard() {
44+
if (schema != nullptr && schema->release != nullptr) {
45+
schema->release(schema);
46+
}
47+
}
48+
};
49+
50+
} // namespace
51+
3852
TEST(ArrowCDataTest, CheckArrowSchemaAndArrayByNanoarrow) {
3953
auto [schema, array] = internal::CreateExampleArrowSchemaAndArrayByNanoarrow();
4054

@@ -86,7 +100,8 @@ TEST_P(ToArrowSchemaTest, PrimitiveType) {
86100
: SchemaField::MakeRequired(kFieldId, std::string(kFieldName),
87101
param.iceberg_type)},
88102
/*schema_id=*/0);
89-
ArrowSchema arrow_schema;
103+
ArrowSchema arrow_schema{};
104+
ArrowSchemaGuard guard{&arrow_schema};
90105
ASSERT_THAT(ToArrowSchema(schema, &arrow_schema), IsOk());
91106

92107
auto imported_schema = ::arrow::ImportSchema(&arrow_schema).ValueOrDie();
@@ -170,7 +185,8 @@ TEST(ToArrowSchemaTest, StructType) {
170185
struct_type)},
171186
/*schema_id=*/0);
172187

173-
ArrowSchema arrow_schema;
188+
ArrowSchema arrow_schema{};
189+
ArrowSchemaGuard guard{&arrow_schema};
174190
ASSERT_THAT(ToArrowSchema(schema, &arrow_schema), IsOk());
175191

176192
auto imported_schema = ::arrow::ImportSchema(&arrow_schema).ValueOrDie();
@@ -202,7 +218,8 @@ TEST(ToArrowSchemaTest, ListType) {
202218
{SchemaField::MakeRequired(kListFieldId, std::string(kListFieldName), list_type)},
203219
/*schema_id=*/0);
204220

205-
ArrowSchema arrow_schema;
221+
ArrowSchema arrow_schema{};
222+
ArrowSchemaGuard guard{&arrow_schema};
206223
ASSERT_THAT(ToArrowSchema(schema, &arrow_schema), IsOk());
207224

208225
auto imported_schema = ::arrow::ImportSchema(&arrow_schema).ValueOrDie();
@@ -237,7 +254,8 @@ TEST(ToArrowSchemaTest, MapType) {
237254
{SchemaField::MakeRequired(kFieldId, std::string(kMapFieldName), map_type)},
238255
/*schema_id=*/0);
239256

240-
ArrowSchema arrow_schema;
257+
ArrowSchema arrow_schema{};
258+
ArrowSchemaGuard guard{&arrow_schema};
241259
ASSERT_THAT(ToArrowSchema(schema, &arrow_schema), IsOk());
242260

243261
auto imported_schema = ::arrow::ImportSchema(&arrow_schema).ValueOrDie();
@@ -278,7 +296,8 @@ TEST_P(FromArrowSchemaTest, PrimitiveType) {
278296
{std::string(kFieldIdKey), std::to_string(kFieldId)}});
279297
auto arrow_schema = ::arrow::schema({::arrow::field(
280298
std::string(kFieldName), param.arrow_type, param.optional, std::move(metadata))});
281-
ArrowSchema exported_schema;
299+
ArrowSchema exported_schema{};
300+
ArrowSchemaGuard guard{&exported_schema};
282301
ASSERT_TRUE(::arrow::ExportSchema(*arrow_schema, &exported_schema).ok());
283302

284303
auto type_result = FromArrowSchema(exported_schema, /*schema_id=*/1);
@@ -353,7 +372,8 @@ TEST(FromArrowSchemaTest, StructType) {
353372
::arrow::key_value_metadata(std::unordered_map<std::string, std::string>{
354373
{std::string(kFieldIdKey), std::to_string(kStructFieldId)}}));
355374
auto arrow_schema = ::arrow::schema({struct_field});
356-
ArrowSchema exported_schema;
375+
ArrowSchema exported_schema{};
376+
ArrowSchemaGuard guard{&exported_schema};
357377
ASSERT_TRUE(::arrow::ExportSchema(*arrow_schema, &exported_schema).ok());
358378

359379
auto schema_result = FromArrowSchema(exported_schema, /*schema_id=*/0);
@@ -403,7 +423,8 @@ TEST(FromArrowSchemaTest, ListType) {
403423
{std::string(kFieldIdKey), std::to_string(kListFieldId)}}));
404424
auto arrow_schema = ::arrow::schema({list_field});
405425

406-
ArrowSchema exported_schema;
426+
ArrowSchema exported_schema{};
427+
ArrowSchemaGuard guard{&exported_schema};
407428
ASSERT_TRUE(::arrow::ExportSchema(*arrow_schema, &exported_schema).ok());
408429

409430
auto schema_result = FromArrowSchema(exported_schema, /*schema_id=*/0);
@@ -453,7 +474,8 @@ TEST(FromArrowSchemaTest, MapType) {
453474
{std::string(kFieldIdKey), std::to_string(kFieldId)}}));
454475
auto arrow_schema = ::arrow::schema({map_field});
455476

456-
ArrowSchema exported_schema;
477+
ArrowSchema exported_schema{};
478+
ArrowSchemaGuard guard{&exported_schema};
457479
ASSERT_TRUE(::arrow::ExportSchema(*arrow_schema, &exported_schema).ok());
458480

459481
auto schema_result = FromArrowSchema(exported_schema, /*schema_id=*/0);

0 commit comments

Comments
 (0)