- if (size >= kalloc_kernmap_size) {
- alloc_map = kernel_map;
-
- if (size > kalloc_largest_allocated)
- /*
- * work around double FREEs of small MALLOCs
- * this used to end up being a nop
- * since the pointer being freed from an
- * alloc backed by the zalloc world could
- * never show up in the kalloc_map... however,
- * the kernel_map is a different issue... since it
- * was released back into the zalloc pool, a pointer
- * would have gotten written over the 'size' that
- * the MALLOC was retaining in the first 4 bytes of
- * the underlying allocation... that pointer ends up
- * looking like a really big size on the 2nd FREE and
- * pushes the kfree into the kernel_map... we
- * end up removing a ton of virutal space before we panic
- * this check causes us to ignore the kfree for a size
- * that must be 'bogus'... note that it might not be due
- * to the above scenario, but it would still be wrong and
- * cause serious damage.
- */
- return;
- } else
- alloc_map = kalloc_map;
- kmem_free(alloc_map, (vm_offset_t)data, size);