g: fix defer bug