diff options
| author | peter <peter@pmikkelsen.com> | 2026-09-04 20:11:09 +0000 |
|---|---|---|
| committer | peter <peter@pmikkelsen.com> | 2026-09-04 20:11:09 +0000 |
| commit | d7c80ae3c76f2dd2e2ce3a39602fa7f04776d9c2 (patch) | |
| tree | fd37dc587f786c22cf69ace481fd8271a4c69449 /src/bin/wrappers.c | |
| parent | fa72ab029ddfcd050f79824bdbea95f77d8f1f60 (diff) | |
Use the same memory-failure mechanism for mallocs
FossilOrigin-Name: fc4f944f1ef599321fac8aa6af72bbe55fb438b4f43800ba37dcfdfa2e6b4c4e
Diffstat (limited to 'src/bin/wrappers.c')
| -rw-r--r-- | src/bin/wrappers.c | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/src/bin/wrappers.c b/src/bin/wrappers.c deleted file mode 100644 index e1e6de7..0000000 --- a/src/bin/wrappers.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2026 Peter Mikkelsen <petermikkelsen10@gmail.com> - * - * This file is part of aplwc. - * - * Aplwc is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Aplwc is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with aplwc. If not, see <https://www.gnu.org/licenses/>. - */ - -#include "aplwc_repl.h" - -static uint64_t malloc_count = 0; - -static uint64_t -malloc_fail_after(void) -{ -#if APLWC_BUILD_TYPE_RELEASE - return UINT64_MAX; -#else - static int setup; - static uint64_t count, count_rec; - - if(!setup){ - setup = 1; - count = getenv_ulong("APLWC_MALLOC_FAIL_AFTER", ULONG_MAX); - count_rec = malloc_fail_after(); - assert(ALWAYS(count == count_rec)); - } - - return count; -#endif -} - -#undef malloc -void * -wrapped_malloc(size_t size) -{ - if(malloc_count++ >= malloc_fail_after()) - return NULL; - else - return malloc(size); -} - -#undef free -void -wrapped_free(void *ptr) -{ - free(ptr); -} |