Skip to content

Commit 84ff80c

Browse files
[cpp_api] Update Deleter to not free null pointers. (#5262)
[SC-53365](https://app.shortcut.com/tiledb-inc/story/53365/cpp-api-invalid-tiledb-object-error-messages-cause-noise) This PR updates the `Deleter` class do nothing when a null pointer is passed to it. Previously it would pass the pointer to `tiledb_***_free`, which would cause an error that gets ignored because most APIs return `void`, and emit an error log message. This resulted in lots of [noise in CI logs](https://github.com/TileDB-Inc/TileDB/actions/runs/10530673714/job/29181096416?pr=5255#step:14:2728). There are some cases in the C++ API where a null handle would be attempted to be freed, like [here](https://github.com/TileDB-Inc/TileDB/blob/9b4e5ea0c8b117716bc96dac71338ffc0d98a2db/tiledb/sm/cpp_api/array.h#L283) or [here](https://github.com/TileDB-Inc/TileDB/blob/9b4e5ea0c8b117716bc96dac71338ffc0d98a2db/tiledb/sm/cpp_api/current_domain.h#L74). Some of them can be eliminated by refactoring the initialization of the smart pointers, but this change is nevertheless valuable, because not all cases can be migrated, and null smart pointers are valid either way. --- TYPE: CPP_API DESC: Fix error log messages when using the `Array` class in the C++ API.
1 parent 097f155 commit 84ff80c

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tiledb/sm/cpp_api/deleter.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,94 +74,140 @@ class Deleter {
7474
/* ********************************* */
7575

7676
void operator()(tiledb_vfs_fh_t* p) const {
77+
if (p == nullptr)
78+
return;
7779
tiledb_vfs_fh_free(&p);
7880
}
7981

8082
void operator()(tiledb_array_t* p) const {
83+
if (p == nullptr)
84+
return;
8185
tiledb_array_free(&p);
8286
}
8387

8488
void operator()(tiledb_subarray_t* p) const {
89+
if (p == nullptr)
90+
return;
8591
tiledb_subarray_free(&p);
8692
}
8793

8894
void operator()(tiledb_query_t* p) const {
95+
if (p == nullptr)
96+
return;
8997
tiledb_query_free(&p);
9098
}
9199

92100
void operator()(tiledb_query_condition_t* p) const {
101+
if (p == nullptr)
102+
return;
93103
tiledb_query_condition_free(&p);
94104
}
95105

96106
void operator()(tiledb_array_schema_t* p) const {
107+
if (p == nullptr)
108+
return;
97109
tiledb_array_schema_free(&p);
98110
}
99111

100112
void operator()(tiledb_array_schema_evolution_t* p) const {
113+
if (p == nullptr)
114+
return;
101115
tiledb_array_schema_evolution_free(&p);
102116
}
103117

104118
void operator()(tiledb_attribute_t* p) const {
119+
if (p == nullptr)
120+
return;
105121
tiledb_attribute_free(&p);
106122
}
107123

108124
void operator()(tiledb_dimension_t* p) const {
125+
if (p == nullptr)
126+
return;
109127
tiledb_dimension_free(&p);
110128
}
111129

112130
void operator()(tiledb_dimension_label_t* p) const {
131+
if (p == nullptr)
132+
return;
113133
tiledb_dimension_label_free(&p);
114134
}
115135

116136
void operator()(tiledb_domain_t* p) const {
137+
if (p == nullptr)
138+
return;
117139
tiledb_domain_free(&p);
118140
}
119141

120142
void operator()(tiledb_current_domain_t* p) const {
143+
if (p == nullptr)
144+
return;
121145
tiledb_current_domain_free(&p);
122146
}
123147

124148
void operator()(tiledb_ndrectangle_t* p) const {
149+
if (p == nullptr)
150+
return;
125151
tiledb_ndrectangle_free(&p);
126152
}
127153

128154
void operator()(tiledb_enumeration_t* p) const {
155+
if (p == nullptr)
156+
return;
129157
tiledb_enumeration_free(&p);
130158
}
131159

132160
void operator()(tiledb_vfs_t* p) const {
161+
if (p == nullptr)
162+
return;
133163
tiledb_vfs_free(&p);
134164
}
135165

136166
void operator()(tiledb_filter_t* p) const {
167+
if (p == nullptr)
168+
return;
137169
tiledb_filter_free(&p);
138170
}
139171

140172
void operator()(tiledb_filter_list_t* p) const {
173+
if (p == nullptr)
174+
return;
141175
tiledb_filter_list_free(&p);
142176
}
143177

144178
void operator()(tiledb_fragment_info_t* p) const {
179+
if (p == nullptr)
180+
return;
145181
tiledb_fragment_info_free(&p);
146182
}
147183

148184
void operator()(tiledb_error_t* p) const {
185+
if (p == nullptr)
186+
return;
149187
tiledb_error_free(&p);
150188
}
151189

152190
void operator()(tiledb_group_t* p) const {
191+
if (p == nullptr)
192+
return;
153193
tiledb_group_free(&p);
154194
}
155195

156196
void operator()(tiledb_consolidation_plan_t* p) const {
197+
if (p == nullptr)
198+
return;
157199
tiledb_consolidation_plan_free(&p);
158200
}
159201

160202
void operator()(tiledb_query_channel_t* p) const {
203+
if (p == nullptr)
204+
return;
161205
tiledb_query_channel_free(ctx_->ptr().get(), &p);
162206
}
163207

164208
void operator()(tiledb_channel_operation_t* p) const {
209+
if (p == nullptr)
210+
return;
165211
tiledb_aggregate_free(ctx_->ptr().get(), &p);
166212
}
167213

0 commit comments

Comments
 (0)