Skip to content

Commit 485df27

Browse files
committed
Op: Remove previous check before delete
Unlike `cbdb::pfree`, the overloaded `delete` keyword checks whether the pointer is null. So we don't need to check if the current pointer is null when call the `delete`.
1 parent 2a67fc0 commit 485df27

6 files changed

Lines changed: 47 additions & 10 deletions

File tree

contrib/pax_storage/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ option(BUILD_PAX_FORMAT "Build pax format lib" OFF)
4747

4848
if (ENBALE_DEBUG)
4949
ADD_DEFINITIONS(-DENBALE_DEBUG)
50-
SET(CMAKE_BUILD_TYPE "Debug")
50+
# Use to build compile_commands.json
51+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
52+
SET(CMAKE_BUILD_TYPE "Debug")
5153
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
5254
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
5355
else()

contrib/pax_storage/src/cpp/access/pax_scanner.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void PaxScanDesc::EndScan(TableScanDesc scan) {
8585

8686
delete desc->reused_buffer_;
8787
delete desc->reader_;
88-
if (desc->filter_) delete desc->filter_;
88+
delete desc->filter_;
8989

9090
#ifdef VEC_BUILD
9191
delete desc->vec_adapter_;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
#include "comm/cbdb_wrappers.h"
3+
#include "comm/gtest_wrappers.h"
4+
5+
namespace pax::tests {
6+
class CommTest : public ::testing::Test {
7+
public:
8+
void SetUp() override {
9+
MemoryContext comm_test_memory_context = AllocSetContextCreate(
10+
(MemoryContext)NULL, "CommTestMemoryContext", 1 * 1024 * 1024,
11+
1 * 1024 * 1024, 1 * 1024 * 1024);
12+
MemoryContextSwitchTo(comm_test_memory_context);
13+
}
14+
15+
void TearDown() override {}
16+
};
17+
18+
TEST_F(CommTest, TestDeleteOperator) {
19+
// In standard C++, we allow the delete null operation
20+
// In Pax, we overloaded the delete operator which used
21+
// `pfree` to free the memory. `pfree` not allow pass NULL.
22+
// But we still need to conform the overloaded delete operation
23+
// to the semantics of c++ which achieve a complete semantic replacement.
24+
auto obj = new int32();
25+
delete obj;
26+
obj = nullptr;
27+
delete obj;
28+
29+
auto array_obj = new int32[10];
30+
delete[] array_obj;
31+
array_obj = nullptr;
32+
delete[] array_obj;
33+
}
34+
35+
} // namespace pax::tests

contrib/pax_storage/src/cpp/storage/columns/pax_columns.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ PaxColumns::PaxColumns(
2626
encoding_option.is_sign = false;
2727
encoding_option.compress_lvl = column_encoding_types[i];
2828

29-
auto pax_non_fixed_column = new PaxNonFixedEncodingColumn(
29+
auto pax_non_fixed_column = new PaxNonFixedEncodingColumn( //
3030
DEFAULT_CAPACITY, std::move(encoding_option));
3131
// current memory will copy from tuple, so should take over it
3232
pax_non_fixed_column->SetMemTakeOver(true);
@@ -76,7 +76,7 @@ PaxColumns::PaxColumns() : row_nums_(0) { data_ = new DataBuffer<char>(0); }
7676

7777
PaxColumns::~PaxColumns() {
7878
for (auto column : columns_) {
79-
if (column) delete column;
79+
delete column;
8080
}
8181
delete data_;
8282
}

contrib/pax_storage/src/cpp/storage/columns/pax_encoding_column.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ PaxEncodingColumn<T>::PaxEncodingColumn(
3131

3232
template <typename T>
3333
PaxEncodingColumn<T>::~PaxEncodingColumn() {
34-
if (encoder_) delete encoder_;
35-
if (decoder_) delete decoder_;
36-
if (shared_data_) delete shared_data_;
37-
if (compressor_) delete compressor_;
34+
delete encoder_;
35+
delete decoder_;
36+
delete shared_data_;
37+
delete compressor_;
3838
}
3939

4040
template <typename T>

contrib/pax_storage/src/cpp/storage/columns/pax_encoding_non_fixed_column.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ PaxNonFixedEncodingColumn::PaxNonFixedEncodingColumn(
4141
}
4242

4343
PaxNonFixedEncodingColumn::~PaxNonFixedEncodingColumn() {
44-
if (compressor_) delete compressor_;
45-
if (shared_data_) delete shared_data_;
44+
delete compressor_;
45+
delete shared_data_;
4646
}
4747

4848
void PaxNonFixedEncodingColumn::Set(DataBuffer<char> *data,

0 commit comments

Comments
 (0)