bug-17892: Removing the use of mkstemps since it's not availble on RHEL5. Also fixing a couple of memory leaks