fix possible double free and possible memory leak

double free was possible due to not setting a freed pointer to zero

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