lib/nbt: Fix a potential memory leak

Soda
BodgeMaster 2022-10-09 10:18:20 +02:00
parent f0092b78d3
commit d5ce50a4a9
1 changed files with 2 additions and 0 deletions

View File

@ -899,10 +899,12 @@ namespace NBT {
ErrorOrVoid List::setElementPointerAt(uint64_t position, Generic* pointer) { ErrorOrVoid List::setElementPointerAt(uint64_t position, Generic* pointer) {
if (this->tags.size() <= position) { if (this->tags.size() <= position) {
delete pointer;
return ErrorOrVoid(true, ErrorCodes::OUT_OF_RANGE); return ErrorOrVoid(true, ErrorCodes::OUT_OF_RANGE);
} }
if (pointer->getTagType() != this->containedType) { if (pointer->getTagType() != this->containedType) {
delete pointer;
return ErrorOrVoid(true, ErrorCodes::INVALID_TYPE); return ErrorOrVoid(true, ErrorCodes::INVALID_TYPE);
} }