fix dereference of already free'd memory

Signed-off-by: Janos Laube <janos.dev@gmail.com>