Fixed bad lock code where we did unlock just before close. This is not the correct behavior. Either one must call fflush() first, or just
close the file so it get flushed, closed  and then unlocked.