Allow for different (but POSIX compliant) behaviour of basename(3) and
prevent a use-after-free in that case in the new sftp-compat code.
POSIX allows basename(3) to either return a pointer to static storage
or modify the passed string and return a pointer to that. OpenBSD does
the former and works as is, but on other platforms "filename" points
into "tmp" which was just freed. This makes the freeing of tmp
consistent with the other variable in the loop.
Pinpointed by the -portable Valgrind regress test. ok djm@ deraadt@