Codechange: Remove manual memory management from CountArticulatedParts (#14336)

Co-authored-by: Henry Wilson <henry@henryandlizzy.uk>
This commit is contained in:
Henry 2025-06-15 21:38:00 +01:00 committed by GitHub
parent cdd555edd5
commit c71515e790
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -80,20 +80,18 @@ uint CountArticulatedParts(EngineID engine_type, bool purchase_window)
* either, so it doesn't matter how many articulated parts there are. */ * either, so it doesn't matter how many articulated parts there are. */
if (!Vehicle::CanAllocateItem()) return 0; if (!Vehicle::CanAllocateItem()) return 0;
Vehicle *v = nullptr; std::unique_ptr<Vehicle> v;
if (!purchase_window) { if (!purchase_window) {
v = new Vehicle(); v = std::make_unique<Vehicle>();
v->engine_type = engine_type; v->engine_type = engine_type;
v->owner = _current_company; v->owner = _current_company;
} }
uint i; uint i;
for (i = 1; i < MAX_ARTICULATED_PARTS; i++) { for (i = 1; i < MAX_ARTICULATED_PARTS; i++) {
if (GetNextArticulatedPart(i, engine_type, v) == EngineID::Invalid()) break; if (GetNextArticulatedPart(i, engine_type, v.get()) == EngineID::Invalid()) break;
} }
delete v;
return i - 1; return i - 1;
} }