Fix potential NULL dereference in alloc_mem_mmap()
[fio.git] / memory.c
index b208320c5d88cc619f7167626e3b7502ded07799..8c06d94d85e7a48ecfb5d8681a8780658f567f6c 100644 (file)
--- a/memory.c
+++ b/memory.c
@@ -158,9 +158,10 @@ static int alloc_mem_mmap(struct thread_data *td, size_t total_mem)
        if (td->orig_buffer == MAP_FAILED) {
                td_verror(td, errno, "mmap");
                td->orig_buffer = NULL;
-               if (td->mmapfd) {
+               if (td->mmapfd != 1) {
                        close(td->mmapfd);
-                       unlink(td->o.mmapfile);
+                       if (td->o.mmapfile)
+                               unlink(td->o.mmapfile);
                }
 
                return 1;