Fix: init_tariff(): cleanup on error
This commit is contained in:
parent
31df676b57
commit
5c0bbf1502
@ -35,6 +35,8 @@ CalcState CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff, char cons
|
|||||||
qCritical() << " ... zone = " << zone;
|
qCritical() << " ... zone = " << zone;
|
||||||
|
|
||||||
if (zone <= 0) {
|
if (zone <= 0) {
|
||||||
|
delete *tariff;
|
||||||
|
*tariff = nullptr;
|
||||||
return calcState.set(CalcState::State::ERROR_PARSING_ZONE_NR);
|
return calcState.set(CalcState::State::ERROR_PARSING_ZONE_NR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,9 +61,13 @@ CalcState CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff, char cons
|
|||||||
|
|
||||||
QString json = fname.readAll();
|
QString json = fname.readAll();
|
||||||
if (! (*tariff)->ParseJson(*tariff, json.toStdString().c_str())) {
|
if (! (*tariff)->ParseJson(*tariff, json.toStdString().c_str())) {
|
||||||
|
delete *tariff;
|
||||||
|
*tariff = nullptr;
|
||||||
return calcState.set(CalcState::State::ERROR_PARSING_TARIFF);
|
return calcState.set(CalcState::State::ERROR_PARSING_TARIFF);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
delete *tariff;
|
||||||
|
*tariff = nullptr;
|
||||||
return calcState.set(CalcState::State::ERROR_LOADING_TARIFF);
|
return calcState.set(CalcState::State::ERROR_LOADING_TARIFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +77,9 @@ CalcState CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff, char cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff) {
|
void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff) {
|
||||||
delete tariff;
|
if (tariff != nullptr) {
|
||||||
|
delete tariff;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
CalcState CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||||
|
Loading…
Reference in New Issue
Block a user