Added filesys lock to file_writing
Fixed double free issue and reopen on mmap file