Fix reference leaks of global handles (ctx, proxy templates).

Signed-off-by: katlogic <kat@lua.cz>