Fix global i variable leak