mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Fix a reference being used after being invalidated (#1352)
Your classic use-after-free bug.
This commit is contained in:
@@ -250,8 +250,11 @@ static void placeSection(Section §ion) {
|
||||
.size =
|
||||
(uint16_t)(freeSpace.address + freeSpace.size - section.org - section.size)}
|
||||
);
|
||||
// **`freeSpace` cannot be reused from this point on**, because `bankMem.insert`
|
||||
// invalidates all references to itself!
|
||||
|
||||
// Resize the original space (address is unmodified)
|
||||
freeSpace.size = section.org - freeSpace.address;
|
||||
bankMem[spaceIdx].size = section.org - bankMem[spaceIdx].address;
|
||||
} else {
|
||||
// The amount of free spaces doesn't change: resize!
|
||||
freeSpace.size -= section.size;
|
||||
|
||||
Reference in New Issue
Block a user