Fix memory leak of constant by no longer needing to make copy of constant.
This commit is contained in:
parent
cf0c44e627
commit
5322e441c5
@ -367,23 +367,11 @@ pub fn run_byte_code(state: &mut DvmState, context: &DvmContext, byte_code: &[u8
|
|||||||
};
|
};
|
||||||
let constant = lib.constants.get(const_id).unwrap();
|
let constant = lib.constants.get(const_id).unwrap();
|
||||||
let DmConstant::String(s) = constant;
|
let DmConstant::String(s) = constant;
|
||||||
|
let pointer = s.as_ptr();
|
||||||
// Alloc memory for constant
|
|
||||||
let size = s.len();
|
|
||||||
let layout = Layout::from_size_align(size, 1).unwrap();
|
|
||||||
let raw_pointer = unsafe { alloc(layout) };
|
|
||||||
|
|
||||||
// Move constant to memory
|
|
||||||
let bytes = s.as_bytes();
|
|
||||||
for i in 0..size {
|
|
||||||
unsafe {
|
|
||||||
raw_pointer.add(i).write(bytes[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store the pointer metadata in target registers.
|
// Store the pointer metadata in target registers.
|
||||||
state.registers[address_register] = DvmValue::USize(raw_pointer as usize);
|
state.registers[address_register] = DvmValue::USize(pointer as usize);
|
||||||
state.registers[size_register] = DvmValue::USize(size);
|
state.registers[size_register] = DvmValue::USize(s.len());
|
||||||
}
|
}
|
||||||
ALLOC_RAW => {
|
ALLOC_RAW => {
|
||||||
// Allocates a raw number of bytes, with the number of bytes determined by the value
|
// Allocates a raw number of bytes, with the number of bytes determined by the value
|
||||||
|
Loading…
Reference in New Issue
Block a user