| 47 | } |
| 48 | |
| 49 | static void *do_xmalloc(size_t size, int gentle) |
| 50 | { |
| 51 | void *ret; |
| 52 | |
| 53 | if (memory_limit_check(size, gentle)) |
| 54 | return NULL; |
| 55 | ret = malloc(size); |
| 56 | if (!ret && !size) |
| 57 | ret = malloc(1); |
| 58 | if (!ret) { |
| 59 | if (!gentle) |
| 60 | die("Out of memory, malloc failed (tried to allocate %lu bytes)", |
| 61 | (unsigned long)size); |
| 62 | else { |
| 63 | error("Out of memory, malloc failed (tried to allocate %lu bytes)", |
| 64 | (unsigned long)size); |
| 65 | return NULL; |
| 66 | } |
| 67 | } |
| 68 | #ifdef XMALLOC_POISON |
| 69 | memset(ret, 0xA5, size); |
| 70 | #endif |
| 71 | return ret; |
| 72 | } |
| 73 | |
| 74 | void *xmalloc(size_t size) |
| 75 | { |
no test coverage detected