]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/kern/tty_ptmx.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / kern / tty_ptmx.c
index d4efb5c12f5a7d6741396b8afb53e22b162bce5e..f505e9243127945181f1e4833166b5f0ae16d06e 100644 (file)
@@ -290,13 +290,14 @@ ptmx_get_ioctl(int minor, int open_flag)
                }
                DEVFS_UNLOCK();
 
-               MALLOC(new_ptmx_ioctl, struct ptmx_ioctl *, sizeof(struct ptmx_ioctl), M_TTYS, M_WAITOK | M_ZERO);
+               new_ptmx_ioctl = kheap_alloc(KM_TTYS, sizeof(struct ptmx_ioctl),
+                   Z_WAITOK | Z_ZERO);
                if (new_ptmx_ioctl == NULL) {
                        return NULL;
                }
 
                if ((new_ptmx_ioctl->pt_tty = ttymalloc()) == NULL) {
-                       FREE(new_ptmx_ioctl, M_TTYS);
+                       kheap_free(KM_TTYS, new_ptmx_ioctl, sizeof(struct ptmx_ioctl));
                        return NULL;
                }
 
@@ -315,7 +316,7 @@ ptmx_get_ioctl(int minor, int open_flag)
                if ((_state.pis_total - _state.pis_free) >= ptmx_max) {
                        ttyfree(new_ptmx_ioctl->pt_tty);
                        DEVFS_UNLOCK();
-                       FREE(new_ptmx_ioctl, M_TTYS);
+                       kheap_free(KM_TTYS, new_ptmx_ioctl, sizeof(struct ptmx_ioctl));
                        return NULL;
                }
 
@@ -323,39 +324,42 @@ ptmx_get_ioctl(int minor, int open_flag)
                if (_state.pis_free == 0) {
                        struct ptmx_ioctl **new_pis_ioctl_list;
                        struct ptmx_ioctl **old_pis_ioctl_list = NULL;
+                       size_t old_pis_total = 0;
 
                        /* Yes. */
-                       MALLOC(new_pis_ioctl_list, struct ptmx_ioctl **, sizeof(struct ptmx_ioctl *) * (_state.pis_total + PTMX_GROW_VECTOR), M_TTYS, M_WAITOK | M_ZERO);
+                       new_pis_ioctl_list = kheap_alloc(KM_TTYS,
+                           sizeof(struct ptmx_ioctl *) * (_state.pis_total + PTMX_GROW_VECTOR),
+                           Z_WAITOK | Z_ZERO);
                        if (new_pis_ioctl_list == NULL) {
                                ttyfree(new_ptmx_ioctl->pt_tty);
                                DEVFS_UNLOCK();
-                               FREE(new_ptmx_ioctl, M_TTYS);
+                               kheap_free(KM_TTYS, new_ptmx_ioctl, sizeof(struct ptmx_ioctl));
                                return NULL;
                        }
 
                        /* If this is not the first time, copy the old over */
                        bcopy(_state.pis_ioctl_list, new_pis_ioctl_list, sizeof(struct ptmx_ioctl *) * _state.pis_total);
                        old_pis_ioctl_list = _state.pis_ioctl_list;
+                       old_pis_total = _state.pis_total;
                        _state.pis_ioctl_list = new_pis_ioctl_list;
                        _state.pis_free += PTMX_GROW_VECTOR;
                        _state.pis_total += PTMX_GROW_VECTOR;
-                       if (old_pis_ioctl_list) {
-                               FREE(old_pis_ioctl_list, M_TTYS);
-                       }
+                       kheap_free(KM_TTYS, old_pis_ioctl_list,
+                           sizeof(struct ptmx_ioctl *) * old_pis_total);
                }
 
                /* is minor in range now? */
                if (minor < 0 || minor >= _state.pis_total) {
                        ttyfree(new_ptmx_ioctl->pt_tty);
                        DEVFS_UNLOCK();
-                       FREE(new_ptmx_ioctl, M_TTYS);
+                       kheap_free(KM_TTYS, new_ptmx_ioctl, sizeof(struct ptmx_ioctl));
                        return NULL;
                }
 
                if (_state.pis_ioctl_list[minor] != NULL) {
                        ttyfree(new_ptmx_ioctl->pt_tty);
                        DEVFS_UNLOCK();
-                       FREE(new_ptmx_ioctl, M_TTYS);
+                       kheap_free(KM_TTYS, new_ptmx_ioctl, sizeof(struct ptmx_ioctl));
 
                        /* Special error value so we know to redrive the open, we've been raced */
                        return (struct ptmx_ioctl*)-1;
@@ -437,7 +441,7 @@ ptmx_free_ioctl(int minor, int open_flag)
                        devfs_remove(old_ptmx_ioctl->pt_devhandle);
                }
                ttyfree(old_ptmx_ioctl->pt_tty);
-               FREE(old_ptmx_ioctl, M_TTYS);
+               kheap_free(KM_TTYS, old_ptmx_ioctl, sizeof(struct ptmx_ioctl));
        }
 
        return 0;     /* Success */