Fixed memleak, increment arg before using!
fixed memleak, increment arg before giving to retval