Skip to content

Commit 42d383c

Browse files
committed
Fix: pfree may free NULL datum
Unlike the DELETE keyword in C++, `cbdb:pfree` does not allow nullptr to be passed in. Therefore, the current commit checks whether it is nullptr before calling `cbdb:pfree`.
1 parent 729a987 commit 42d383c

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

contrib/pax_storage/src/cpp/storage/micro_partition_stats.cc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@ static void SumStatisticsInfoCombine(
335335

336336
if (!sumtypbyval &&
337337
cbdb::DatumToPointer(newval) != cbdb::DatumToPointer(left_sum)) {
338-
cbdb::Pfree(cbdb::DatumToPointer(newval));
338+
if (newval)
339+
cbdb::Pfree(cbdb::DatumToPointer(newval));
339340
}
340341

341342
} else {
@@ -496,7 +497,8 @@ ::pax::stats::MicroPartitionStatisticsInfo *MicroPartitionStats::Serialize() {
496497
// 1. newval won't be a toast
497498
// 2. the `newval` alloc in `final_func` which not used the
498499
// PAX_NEW to alloc, can't use the PAX_DELETE to delete it
499-
cbdb::Pfree(cbdb::DatumToPointer(sum_stats_[column_index].result));
500+
if (sum_stats_[column_index].result)
501+
cbdb::Pfree(cbdb::DatumToPointer(sum_stats_[column_index].result));
500502
sum_stats_[column_index].result =
501503
cbdb::datumCopy(newval, sum_stats_[column_index].rettypbyval,
502504
sum_stats_[column_index].rettyplen);
@@ -655,7 +657,8 @@ void MicroPartitionStats::MergeRawInfo(
655657
if (!sum_stat->rettypbyval &&
656658
cbdb::DatumToPointer(newval) !=
657659
cbdb::DatumToPointer(sum_stat->result)) {
658-
cbdb::Pfree(cbdb::DatumToPointer(sum_stat->result));
660+
if (sum_stat->result)
661+
cbdb::Pfree(cbdb::DatumToPointer(sum_stat->result));
659662
}
660663
sum_stat->result =
661664
cbdb::datumCopy(newval, sum_stat->rettyplen, sum_stat->rettypbyval);
@@ -786,7 +789,8 @@ void MicroPartitionStats::MergeTo(MicroPartitionStats *stats) {
786789
if (!left_sum_stat->transtypbyval &&
787790
cbdb::DatumToPointer(newval) !=
788791
cbdb::DatumToPointer(right_sum_stat->result)) {
789-
cbdb::Pfree(cbdb::DatumToPointer(right_sum_stat->result));
792+
if (right_sum_stat->result)
793+
cbdb::Pfree(cbdb::DatumToPointer(right_sum_stat->result));
790794
right_sum_stat->result = cbdb::datumCopy(
791795
newval, right_sum_stat->rettypbyval, right_sum_stat->rettyplen);
792796
} else {
@@ -806,7 +810,8 @@ void MicroPartitionStats::MergeTo(MicroPartitionStats *stats) {
806810
if (!left_sum_stat->rettypbyval &&
807811
cbdb::DatumToPointer(newval) !=
808812
cbdb::DatumToPointer(left_sum_stat->result)) {
809-
cbdb::Pfree(cbdb::DatumToPointer(left_sum_stat->result));
813+
if (left_sum_stat->result)
814+
cbdb::Pfree(cbdb::DatumToPointer(left_sum_stat->result));
810815
}
811816
left_sum_stat->result = cbdb::datumCopy(newval, left_sum_stat->rettyplen,
812817
left_sum_stat->rettypbyval);
@@ -910,7 +915,8 @@ void MicroPartitionStats::AddNonNullColumn(int column_index, Datum value,
910915
if (!sum_stats_[column_index].transtypbyval &&
911916
cbdb::DatumToPointer(newval) !=
912917
cbdb::DatumToPointer(sum_stats_[column_index].result)) {
913-
cbdb::Pfree(cbdb::DatumToPointer(sum_stats_[column_index].result));
918+
if (sum_stats_[column_index].result)
919+
cbdb::Pfree(cbdb::DatumToPointer(sum_stats_[column_index].result));
914920
sum_stats_[column_index].result = newval;
915921
} else {
916922
sum_stats_[column_index].result = newval;

0 commit comments

Comments
 (0)