Fix double free

This commit is contained in:
Woosuk Kwon 2023-02-14 09:14:05 +00:00
parent c80ed212a1
commit c128c2ed03

View File

@ -115,13 +115,13 @@ class BlockSpaceManager:
last_block = block_table[-1] last_block = block_table[-1]
assert last_block.device == Device.GPU assert last_block.device == Device.GPU
if last_block.ref_count == 1: if last_block.ref_count == 1:
# Append. # Not shared with other sequences. Appendable.
return None return None
else: else:
# The last block is shared with other sequences. # The last block is shared with other sequences.
# Copy on Write: Allocate a new block and copy the tokens. # Copy on Write: Allocate a new block and copy the tokens.
new_block = self.gpu_allocator.allocate() new_block = self.gpu_allocator.allocate()
block_table.append(new_block) block_table[-1] = new_block
self.gpu_allocator.free(last_block) self.gpu_allocator.free(last_block)
return last_block.block_number, new_block.block_number return last_block.block_number, new_block.block_number