/* $OpenBSD: malloc_ulimit1.c,v 1.5 2019/06/12 11:31:36 bluhm Exp $ */ /* Public Domain, 2006, Otto Moerbeek */ #include #include #include #include #include #include /* * This code tries to trigger the case present in -current as of April * 2006) where the allocation of the region itself succeeds, but the * page dir entry pages fails. * This in turn trips a "hole in directories" error. * Having a large (512M) ulimit -m helps a lot in triggering the * problem. Note that you may need to run this test multiple times to * see the error. */ #define STARTI 1300 #define FACTOR 1024 /* This test takes forever with junking turned on. */ char *malloc_options = "jj"; int main() { struct rlimit lim; size_t sz; int i; void *p; if (getrlimit(RLIMIT_DATA, &lim) == -1) err(1, "getrlimit"); sz = lim.rlim_cur / FACTOR; for (i = STARTI; i >= 0; i--) { size_t len = (sz-i) * FACTOR; p = malloc(len); free(p); free(malloc(4096)); } return (0); }