Fix memory errors

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>