mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +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 =
|
.size =
|
||||||
(uint16_t)(freeSpace.address + freeSpace.size - section.org - section.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)
|
// Resize the original space (address is unmodified)
|
||||||
freeSpace.size = section.org - freeSpace.address;
|
bankMem[spaceIdx].size = section.org - bankMem[spaceIdx].address;
|
||||||
} else {
|
} else {
|
||||||
// The amount of free spaces doesn't change: resize!
|
// The amount of free spaces doesn't change: resize!
|
||||||
freeSpace.size -= section.size;
|
freeSpace.size -= section.size;
|
||||||
|
|||||||
Reference in New Issue
Block a user