add type casting for size vaule and fix handle leak