Skip to content

Commit

Permalink
ICU-21387 measunit: check for nullptr before calling delete
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovdm authored and sffc committed Dec 9, 2020
1 parent ceeb53a commit f3bf3d4
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions icu4c/source/i18n/measunit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2139,7 +2139,9 @@ MeasureUnit &MeasureUnit::operator=(const MeasureUnit &other) {
if (this == &other) {
return *this;
}
delete fImpl;
if (fImpl != nullptr) {
delete fImpl;
}
if (other.fImpl) {
ErrorCode localStatus;
fImpl = new MeasureUnitImpl(other.fImpl->copy(localStatus));
Expand All @@ -2160,7 +2162,9 @@ MeasureUnit &MeasureUnit::operator=(MeasureUnit &&other) noexcept {
if (this == &other) {
return *this;
}
delete fImpl;
if (fImpl != nullptr) {
delete fImpl;
}
fImpl = other.fImpl;
other.fImpl = nullptr;
fTypeId = other.fTypeId;
Expand All @@ -2173,8 +2177,10 @@ MeasureUnit *MeasureUnit::clone() const {
}

MeasureUnit::~MeasureUnit() {
delete fImpl;
fImpl = nullptr;
if (fImpl != nullptr) {
delete fImpl;
fImpl = nullptr;
}
}

const char *MeasureUnit::getType() const {
Expand Down Expand Up @@ -2330,8 +2336,10 @@ void MeasureUnit::initCurrency(StringPiece isoCurrency) {
void MeasureUnit::setTo(int32_t typeId, int32_t subTypeId) {
fTypeId = typeId;
fSubTypeId = subTypeId;
delete fImpl;
fImpl = nullptr;
if (fImpl != nullptr) {
delete fImpl;
fImpl = nullptr;
}
}

int32_t MeasureUnit::getOffset() const {
Expand Down

0 comments on commit f3bf3d4

Please sign in to comment.