static void mm_free()

in ext/mmap/mmap.c [120:153]


static void mm_free(mm_ipc *i_mm) {
#if HAVE_SEMCTL && HAVE_SHMCTL
    if (i_mm->t->flag & MM_IPC) {
        struct shmid_ds buf;

        if (shmctl(i_mm->t->shmid, IPC_STAT, &buf) != -1) {
            if (buf.shm_nattch == 1 && (i_mm->t->flag & MM_TMP)) {
                semctl(i_mm->t->semid, 0, IPC_RMID);
                if (i_mm->t->template) {
                    unlink(i_mm->t->template);
                    free(i_mm->t->template);
                }
            }
        }
        shmdt(i_mm->t);
    } else {
        free(i_mm->t);
    }
#endif
    if (i_mm->t->path) {
        munmap(i_mm->t->addr, i_mm->t->len);
        if (i_mm->t->path != (char *)-1) {
            if (i_mm->t->real < i_mm->t->len &&
                i_mm->t->vscope != MAP_PRIVATE &&
                truncate(i_mm->t->path, i_mm->t->real) == -1) {
                free(i_mm->t->path);
                free(i_mm);
                rb_raise(rb_eTypeError, "truncate");
            }
            free(i_mm->t->path);
        }
    }
    free(i_mm);
}