Fixed few resource leak issues

Signed-off-by: Daan Hoogland <daan@onecht.net>