core: fix use after free error

Signed-off-by: Hagen Paul Pfeifer <hagen@jauu.net>