title: Why doesn't free execute munmap?
body: <p>I have the following code:</p>
  
  <pre><code>     unsigned char *p = (unsigned char *)valloc(page_size);
       if (!p) {                 
               ret = -1;
               goto out;
       }
       printf("valloc: allocated %d bytes, virtual address: %p\n", page_size, p);
  
       memset(p, 0xFF, page_size);
       memcpy(p, s, sizeof(s));
  
       trace_mem(p, sizeof(s));
       printf("Memory: %p -  press any key\n", p);
       getchar();
  
       if (ioctl(fd, MY_IOC_PATCH) == -1) {
              fprintf(stderr, "ioctl %s error(%d): %s\n ", "MY_IOC_PATCH", errno, strerror(errno));
              ret = -1;
              goto out;
       }
  
       if (p) {
               printf("free: freed %d bytes, virtual address: %p\n", page_size, p);
               free(p);
       }
        .........................
  </code></pre>
  
  <p>Then I use strace to observe system calls: strace ./my_program I get the following:</p>
  
  <pre><code>fstat64(1, {st_mode=S_IFREG|0644, st_size=1533, ...}) = 0
  mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =      0xb7730000
  brk(0)                                  = 0x9d81000
  brk(0x9da4000)                          = 0x9da4000
  fstat64(0, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
  mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb772f000
  read(0, "\n", 1024)                     = 1
  ioctl(3, RTC_IRQP_SET, 0x1000)          = 0
  read(0, "\n", 1024)                     = 1
  ioctl(3, RTC_EPOCH_READ, 0x9d82000)     = 0
  read(0, "\n", 1024)                     = 1
  close(3)                                = 0
  valloc: allocated 4096 bytes, virtual address: 0x9d82000
  </code></pre>
  
  <p>After the first IOCTL I don't see munlock. I suppose that free must use munlock to unmap memory, but it doesn't cause. What is the reason for that?</p>