| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/bash/src/lib/malloc/malloc.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* malloc.c - dynamic memory allocation for bash. */ | - | ||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||
| 3 | /* Copyright (C) 1985-2005 Free Software Foundation, Inc. | - | ||||||||||||||||||||||||
| 4 | - | |||||||||||||||||||||||||
| 5 | This file is part of GNU Bash, the Bourne-Again SHell. | - | ||||||||||||||||||||||||
| 6 | - | |||||||||||||||||||||||||
| 7 | Bash is free software: you can redistribute it and/or modify | - | ||||||||||||||||||||||||
| 8 | it under the terms of the GNU General Public License as published by | - | ||||||||||||||||||||||||
| 9 | the Free Software Foundation, either version 3 of the License, or | - | ||||||||||||||||||||||||
| 10 | (at your option) any later version. | - | ||||||||||||||||||||||||
| 11 | - | |||||||||||||||||||||||||
| 12 | Bash is distributed in the hope that it will be useful, | - | ||||||||||||||||||||||||
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | - | ||||||||||||||||||||||||
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | - | ||||||||||||||||||||||||
| 15 | GNU General Public License for more details. | - | ||||||||||||||||||||||||
| 16 | - | |||||||||||||||||||||||||
| 17 | You should have received a copy of the GNU General Public License | - | ||||||||||||||||||||||||
| 18 | along with Bash. If not, see <http://www.gnu.org/licenses/>. | - | ||||||||||||||||||||||||
| 19 | */ | - | ||||||||||||||||||||||||
| 20 | - | |||||||||||||||||||||||||
| 21 | /* | - | ||||||||||||||||||||||||
| 22 | * @(#)nmalloc.c 1 (Caltech) 2/21/82 | - | ||||||||||||||||||||||||
| 23 | * | - | ||||||||||||||||||||||||
| 24 | * U of M Modified: 20 Jun 1983 ACT: strange hacks for Emacs | - | ||||||||||||||||||||||||
| 25 | * | - | ||||||||||||||||||||||||
| 26 | * Nov 1983, Mike@BRL, Added support for 4.1C/4.2 BSD. | - | ||||||||||||||||||||||||
| 27 | * | - | ||||||||||||||||||||||||
| 28 | * This is a very fast storage allocator. It allocates blocks of a small | - | ||||||||||||||||||||||||
| 29 | * number of different sizes, and keeps free lists of each size. Blocks | - | ||||||||||||||||||||||||
| 30 | * that don't exactly fit are passed up to the next larger size. In this | - | ||||||||||||||||||||||||
| 31 | * implementation, the available sizes are (2^n)-4 (or -16) bytes long. | - | ||||||||||||||||||||||||
| 32 | * This is designed for use in a program that uses vast quantities of | - | ||||||||||||||||||||||||
| 33 | * memory, but bombs when it runs out. To make it a little better, it | - | ||||||||||||||||||||||||
| 34 | * warns the user when he starts to get near the end. | - | ||||||||||||||||||||||||
| 35 | * | - | ||||||||||||||||||||||||
| 36 | * June 84, ACT: modified rcheck code to check the range given to malloc, | - | ||||||||||||||||||||||||
| 37 | * rather than the range determined by the 2-power used. | - | ||||||||||||||||||||||||
| 38 | * | - | ||||||||||||||||||||||||
| 39 | * Jan 85, RMS: calls malloc_warning to issue warning on nearly full. | - | ||||||||||||||||||||||||
| 40 | * No longer Emacs-specific; can serve as all-purpose malloc for GNU. | - | ||||||||||||||||||||||||
| 41 | * You should call malloc_init to reinitialize after loading dumped Emacs. | - | ||||||||||||||||||||||||
| 42 | * Call malloc_stats to get info on memory stats if MALLOC_STATS turned on. | - | ||||||||||||||||||||||||
| 43 | * realloc knows how to return same block given, just changing its size, | - | ||||||||||||||||||||||||
| 44 | * if the power of 2 is correct. | - | ||||||||||||||||||||||||
| 45 | */ | - | ||||||||||||||||||||||||
| 46 | - | |||||||||||||||||||||||||
| 47 | /* | - | ||||||||||||||||||||||||
| 48 | * nextf[i] is the pointer to the next free block of size 2^(i+3). The | - | ||||||||||||||||||||||||
| 49 | * smallest allocatable block is 8 bytes. The overhead information will | - | ||||||||||||||||||||||||
| 50 | * go in the first int of the block, and the returned pointer will point | - | ||||||||||||||||||||||||
| 51 | * to the second. | - | ||||||||||||||||||||||||
| 52 | */ | - | ||||||||||||||||||||||||
| 53 | - | |||||||||||||||||||||||||
| 54 | /* Define MEMSCRAMBLE to have free() write 0xcf into memory as it's freed, to | - | ||||||||||||||||||||||||
| 55 | uncover callers that refer to freed memory, and to have malloc() write 0xdf | - | ||||||||||||||||||||||||
| 56 | into memory as it's allocated to avoid referring to previous contents. */ | - | ||||||||||||||||||||||||
| 57 | - | |||||||||||||||||||||||||
| 58 | /* SCO 3.2v4 getcwd and possibly other libc routines fail with MEMSCRAMBLE; | - | ||||||||||||||||||||||||
| 59 | handled by configure. */ | - | ||||||||||||||||||||||||
| 60 | - | |||||||||||||||||||||||||
| 61 | #if defined (HAVE_CONFIG_H) | - | ||||||||||||||||||||||||
| 62 | # include <config.h> | - | ||||||||||||||||||||||||
| 63 | #endif /* HAVE_CONFIG_H */ | - | ||||||||||||||||||||||||
| 64 | - | |||||||||||||||||||||||||
| 65 | #if defined (SHELL) | - | ||||||||||||||||||||||||
| 66 | # include "bashtypes.h" | - | ||||||||||||||||||||||||
| 67 | # include "stdc.h" | - | ||||||||||||||||||||||||
| 68 | #else | - | ||||||||||||||||||||||||
| 69 | # include <sys/types.h> | - | ||||||||||||||||||||||||
| 70 | #endif | - | ||||||||||||||||||||||||
| 71 | - | |||||||||||||||||||||||||
| 72 | #if defined (HAVE_UNISTD_H) | - | ||||||||||||||||||||||||
| 73 | # include <unistd.h> | - | ||||||||||||||||||||||||
| 74 | #endif | - | ||||||||||||||||||||||||
| 75 | - | |||||||||||||||||||||||||
| 76 | /* Determine which kind of system this is. */ | - | ||||||||||||||||||||||||
| 77 | #include <signal.h> | - | ||||||||||||||||||||||||
| 78 | - | |||||||||||||||||||||||||
| 79 | #if defined (HAVE_STRING_H) | - | ||||||||||||||||||||||||
| 80 | # include <string.h> | - | ||||||||||||||||||||||||
| 81 | #else | - | ||||||||||||||||||||||||
| 82 | # include <strings.h> | - | ||||||||||||||||||||||||
| 83 | #endif | - | ||||||||||||||||||||||||
| 84 | #include <errno.h> | - | ||||||||||||||||||||||||
| 85 | #include <stdio.h> | - | ||||||||||||||||||||||||
| 86 | - | |||||||||||||||||||||||||
| 87 | /* Define getpagesize () if the system does not. */ | - | ||||||||||||||||||||||||
| 88 | #ifndef HAVE_GETPAGESIZE | - | ||||||||||||||||||||||||
| 89 | # include "getpagesize.h" | - | ||||||||||||||||||||||||
| 90 | #endif | - | ||||||||||||||||||||||||
| 91 | - | |||||||||||||||||||||||||
| 92 | #include "imalloc.h" | - | ||||||||||||||||||||||||
| 93 | #ifdef MALLOC_STATS | - | ||||||||||||||||||||||||
| 94 | # include "mstats.h" | - | ||||||||||||||||||||||||
| 95 | #endif | - | ||||||||||||||||||||||||
| 96 | #ifdef MALLOC_REGISTER | - | ||||||||||||||||||||||||
| 97 | # include "table.h" | - | ||||||||||||||||||||||||
| 98 | #endif | - | ||||||||||||||||||||||||
| 99 | #ifdef MALLOC_WATCH | - | ||||||||||||||||||||||||
| 100 | # include "watch.h" | - | ||||||||||||||||||||||||
| 101 | #endif | - | ||||||||||||||||||||||||
| 102 | - | |||||||||||||||||||||||||
| 103 | #ifdef powerof2 | - | ||||||||||||||||||||||||
| 104 | # undef powerof2 | - | ||||||||||||||||||||||||
| 105 | #endif | - | ||||||||||||||||||||||||
| 106 | /* Could also use (((x) & -(x)) == (x)) */ | - | ||||||||||||||||||||||||
| 107 | #define powerof2(x) ((((x) - 1) & (x)) == 0) | - | ||||||||||||||||||||||||
| 108 | - | |||||||||||||||||||||||||
| 109 | /* System-specific omissions. */ | - | ||||||||||||||||||||||||
| 110 | #ifdef HPUX | - | ||||||||||||||||||||||||
| 111 | # define NO_VALLOC | - | ||||||||||||||||||||||||
| 112 | #endif | - | ||||||||||||||||||||||||
| 113 | - | |||||||||||||||||||||||||
| 114 | #define NBUCKETS 30 | - | ||||||||||||||||||||||||
| 115 | - | |||||||||||||||||||||||||
| 116 | #define ISALLOC ((char) 0xf7) /* magic byte that implies allocation */ | - | ||||||||||||||||||||||||
| 117 | #define ISFREE ((char) 0x54) /* magic byte that implies free block */ | - | ||||||||||||||||||||||||
| 118 | /* this is for error checking only */ | - | ||||||||||||||||||||||||
| 119 | #define ISMEMALIGN ((char) 0xd6) /* Stored before the value returned by | - | ||||||||||||||||||||||||
| 120 | memalign, with the rest of the word | - | ||||||||||||||||||||||||
| 121 | being the distance to the true | - | ||||||||||||||||||||||||
| 122 | beginning of the block. */ | - | ||||||||||||||||||||||||
| 123 | - | |||||||||||||||||||||||||
| 124 | - | |||||||||||||||||||||||||
| 125 | /* We have a flag indicating whether memory is allocated, an index in | - | ||||||||||||||||||||||||
| 126 | nextf[], a size field, and a sentinel value to determine whether or | - | ||||||||||||||||||||||||
| 127 | not a caller wrote before the start of allocated memory; to realloc() | - | ||||||||||||||||||||||||
| 128 | memory we either copy mh_nbytes or just change mh_nbytes if there is | - | ||||||||||||||||||||||||
| 129 | enough room in the block for the new size. Range checking is always | - | ||||||||||||||||||||||||
| 130 | done. */ | - | ||||||||||||||||||||||||
| 131 | union mhead { | - | ||||||||||||||||||||||||
| 132 | bits64_t mh_align; /* 8 */ | - | ||||||||||||||||||||||||
| 133 | struct { | - | ||||||||||||||||||||||||
| 134 | char mi_alloc; /* ISALLOC or ISFREE */ /* 1 */ | - | ||||||||||||||||||||||||
| 135 | char mi_index; /* index in nextf[] */ /* 1 */ | - | ||||||||||||||||||||||||
| 136 | /* Remainder are valid only when block is allocated */ | - | ||||||||||||||||||||||||
| 137 | u_bits16_t mi_magic2; /* should be == MAGIC2 */ /* 2 */ | - | ||||||||||||||||||||||||
| 138 | u_bits32_t mi_nbytes; /* # of bytes allocated */ /* 4 */ | - | ||||||||||||||||||||||||
| 139 | } minfo; | - | ||||||||||||||||||||||||
| 140 | }; | - | ||||||||||||||||||||||||
| 141 | #define mh_alloc minfo.mi_alloc | - | ||||||||||||||||||||||||
| 142 | #define mh_index minfo.mi_index | - | ||||||||||||||||||||||||
| 143 | #define mh_nbytes minfo.mi_nbytes | - | ||||||||||||||||||||||||
| 144 | #define mh_magic2 minfo.mi_magic2 | - | ||||||||||||||||||||||||
| 145 | - | |||||||||||||||||||||||||
| 146 | #define MOVERHEAD sizeof(union mhead) | - | ||||||||||||||||||||||||
| 147 | #define MALIGN_MASK 7 /* one less than desired alignment */ | - | ||||||||||||||||||||||||
| 148 | - | |||||||||||||||||||||||||
| 149 | typedef union _malloc_guard { | - | ||||||||||||||||||||||||
| 150 | char s[4]; | - | ||||||||||||||||||||||||
| 151 | u_bits32_t i; | - | ||||||||||||||||||||||||
| 152 | } mguard_t; | - | ||||||||||||||||||||||||
| 153 | - | |||||||||||||||||||||||||
| 154 | /* Access free-list pointer of a block. | - | ||||||||||||||||||||||||
| 155 | It is stored at block + sizeof (char *). | - | ||||||||||||||||||||||||
| 156 | This is not a field in the minfo structure member of union mhead | - | ||||||||||||||||||||||||
| 157 | because we want sizeof (union mhead) | - | ||||||||||||||||||||||||
| 158 | to describe the overhead for when the block is in use, | - | ||||||||||||||||||||||||
| 159 | and we do not want the free-list pointer to count in that. */ | - | ||||||||||||||||||||||||
| 160 | - | |||||||||||||||||||||||||
| 161 | #define CHAIN(a) \ | - | ||||||||||||||||||||||||
| 162 | (*(union mhead **) (sizeof (char *) + (char *) (a))) | - | ||||||||||||||||||||||||
| 163 | - | |||||||||||||||||||||||||
| 164 | /* To implement range checking, we write magic values in at the beginning | - | ||||||||||||||||||||||||
| 165 | and end of each allocated block, and make sure they are undisturbed | - | ||||||||||||||||||||||||
| 166 | whenever a free or a realloc occurs. */ | - | ||||||||||||||||||||||||
| 167 | - | |||||||||||||||||||||||||
| 168 | /* Written in the 2 bytes before the block's real space (-4 bytes) */ | - | ||||||||||||||||||||||||
| 169 | #define MAGIC2 0x5555 | - | ||||||||||||||||||||||||
| 170 | #define MSLOP 4 /* 4 bytes extra for u_bits32_t size */ | - | ||||||||||||||||||||||||
| 171 | - | |||||||||||||||||||||||||
| 172 | /* How many bytes are actually allocated for a request of size N -- | - | ||||||||||||||||||||||||
| 173 | rounded up to nearest multiple of 8 after accounting for malloc | - | ||||||||||||||||||||||||
| 174 | overhead. */ | - | ||||||||||||||||||||||||
| 175 | #define ALLOCATED_BYTES(n) \ | - | ||||||||||||||||||||||||
| 176 | (((n) + MOVERHEAD + MSLOP + MALIGN_MASK) & ~MALIGN_MASK) | - | ||||||||||||||||||||||||
| 177 | - | |||||||||||||||||||||||||
| 178 | #define ASSERT(p) \ | - | ||||||||||||||||||||||||
| 179 | do \ | - | ||||||||||||||||||||||||
| 180 | { \ | - | ||||||||||||||||||||||||
| 181 | if (!(p)) xbotch((PTR_T)0, ERR_ASSERT_FAILED, CPP_STRING(p), file, line); \ | - | ||||||||||||||||||||||||
| 182 | } \ | - | ||||||||||||||||||||||||
| 183 | while (0) | - | ||||||||||||||||||||||||
| 184 | - | |||||||||||||||||||||||||
| 185 | /* Minimum and maximum bucket indices for block splitting (and to bound | - | ||||||||||||||||||||||||
| 186 | the search for a block to split). */ | - | ||||||||||||||||||||||||
| 187 | #define SPLIT_MIN 2 /* XXX - was 3 */ | - | ||||||||||||||||||||||||
| 188 | #define SPLIT_MID 11 | - | ||||||||||||||||||||||||
| 189 | #define SPLIT_MAX 14 | - | ||||||||||||||||||||||||
| 190 | - | |||||||||||||||||||||||||
| 191 | /* Minimum and maximum bucket indices for block coalescing. */ | - | ||||||||||||||||||||||||
| 192 | #define COMBINE_MIN 2 | - | ||||||||||||||||||||||||
| 193 | #define COMBINE_MAX (pagebucket - 1) /* XXX */ | - | ||||||||||||||||||||||||
| 194 | - | |||||||||||||||||||||||||
| 195 | #define LESSCORE_MIN 10 | - | ||||||||||||||||||||||||
| 196 | #define LESSCORE_FRC 13 | - | ||||||||||||||||||||||||
| 197 | - | |||||||||||||||||||||||||
| 198 | #define STARTBUCK 1 | - | ||||||||||||||||||||||||
| 199 | - | |||||||||||||||||||||||||
| 200 | /* Flags for the internal functions. */ | - | ||||||||||||||||||||||||
| 201 | #define MALLOC_WRAPPER 0x01 /* wrapper function */ | - | ||||||||||||||||||||||||
| 202 | #define MALLOC_INTERNAL 0x02 /* internal function calling another */ | - | ||||||||||||||||||||||||
| 203 | #define MALLOC_NOTRACE 0x04 /* don't trace this allocation or free */ | - | ||||||||||||||||||||||||
| 204 | #define MALLOC_NOREG 0x08 /* don't register this allocation or free */ | - | ||||||||||||||||||||||||
| 205 | - | |||||||||||||||||||||||||
| 206 | /* Future use. */ | - | ||||||||||||||||||||||||
| 207 | #define ERR_DUPFREE 0x01 | - | ||||||||||||||||||||||||
| 208 | #define ERR_UNALLOC 0x02 | - | ||||||||||||||||||||||||
| 209 | #define ERR_UNDERFLOW 0x04 | - | ||||||||||||||||||||||||
| 210 | #define ERR_ASSERT_FAILED 0x08 | - | ||||||||||||||||||||||||
| 211 | - | |||||||||||||||||||||||||
| 212 | /* Evaluates to true if NB is appropriate for bucket NU. NB is adjusted | - | ||||||||||||||||||||||||
| 213 | appropriately by the caller to account for malloc overhead. This only | - | ||||||||||||||||||||||||
| 214 | checks that the recorded size is not too big for the bucket. We | - | ||||||||||||||||||||||||
| 215 | can't check whether or not it's in between NU and NU-1 because we | - | ||||||||||||||||||||||||
| 216 | might have encountered a busy bucket when allocating and moved up to | - | ||||||||||||||||||||||||
| 217 | the next size. */ | - | ||||||||||||||||||||||||
| 218 | #define IN_BUCKET(nb, nu) ((nb) <= binsizes[(nu)]) | - | ||||||||||||||||||||||||
| 219 | - | |||||||||||||||||||||||||
| 220 | /* Use this when we want to be sure that NB is in bucket NU. */ | - | ||||||||||||||||||||||||
| 221 | #define RIGHT_BUCKET(nb, nu) \ | - | ||||||||||||||||||||||||
| 222 | (((nb) > binsizes[(nu)-1]) && ((nb) <= binsizes[(nu)])) | - | ||||||||||||||||||||||||
| 223 | - | |||||||||||||||||||||||||
| 224 | /* nextf[i] is free list of blocks of size 2**(i + 3) */ | - | ||||||||||||||||||||||||
| 225 | - | |||||||||||||||||||||||||
| 226 | static union mhead *nextf[NBUCKETS]; | - | ||||||||||||||||||||||||
| 227 | - | |||||||||||||||||||||||||
| 228 | /* busy[i] is nonzero while allocation or free of block size i is in progress. */ | - | ||||||||||||||||||||||||
| 229 | - | |||||||||||||||||||||||||
| 230 | static char busy[NBUCKETS]; | - | ||||||||||||||||||||||||
| 231 | - | |||||||||||||||||||||||||
| 232 | static int pagesz; /* system page size. */ | - | ||||||||||||||||||||||||
| 233 | static int pagebucket; /* bucket for requests a page in size */ | - | ||||||||||||||||||||||||
| 234 | static int maxbuck; /* highest bucket receiving allocation request. */ | - | ||||||||||||||||||||||||
| 235 | - | |||||||||||||||||||||||||
| 236 | static char *memtop; /* top of heap */ | - | ||||||||||||||||||||||||
| 237 | - | |||||||||||||||||||||||||
| 238 | static const unsigned long binsizes[NBUCKETS] = { | - | ||||||||||||||||||||||||
| 239 | 8UL, 16UL, 32UL, 64UL, 128UL, 256UL, 512UL, 1024UL, 2048UL, 4096UL, | - | ||||||||||||||||||||||||
| 240 | 8192UL, 16384UL, 32768UL, 65536UL, 131072UL, 262144UL, 524288UL, | - | ||||||||||||||||||||||||
| 241 | 1048576UL, 2097152UL, 4194304UL, 8388608UL, 16777216UL, 33554432UL, | - | ||||||||||||||||||||||||
| 242 | 67108864UL, 134217728UL, 268435456UL, 536870912UL, 1073741824UL, | - | ||||||||||||||||||||||||
| 243 | 2147483648UL, 4294967295UL | - | ||||||||||||||||||||||||
| 244 | }; | - | ||||||||||||||||||||||||
| 245 | - | |||||||||||||||||||||||||
| 246 | /* binsizes[x] == (1 << ((x) + 3)) */ | - | ||||||||||||||||||||||||
| 247 | #define binsize(x) binsizes[(x)] | - | ||||||||||||||||||||||||
| 248 | - | |||||||||||||||||||||||||
| 249 | #if !defined (errno) | - | ||||||||||||||||||||||||
| 250 | extern int errno; | - | ||||||||||||||||||||||||
| 251 | #endif | - | ||||||||||||||||||||||||
| 252 | - | |||||||||||||||||||||||||
| 253 | /* Declarations for internal functions */ | - | ||||||||||||||||||||||||
| 254 | static PTR_T internal_malloc __P((size_t, const char *, int, int)); | - | ||||||||||||||||||||||||
| 255 | static PTR_T internal_realloc __P((PTR_T, size_t, const char *, int, int)); | - | ||||||||||||||||||||||||
| 256 | static void internal_free __P((PTR_T, const char *, int, int)); | - | ||||||||||||||||||||||||
| 257 | static PTR_T internal_memalign __P((size_t, size_t, const char *, int, int)); | - | ||||||||||||||||||||||||
| 258 | #ifndef NO_CALLOC | - | ||||||||||||||||||||||||
| 259 | static PTR_T internal_calloc __P((size_t, size_t, const char *, int, int)); | - | ||||||||||||||||||||||||
| 260 | static void internal_cfree __P((PTR_T, const char *, int, int)); | - | ||||||||||||||||||||||||
| 261 | #endif | - | ||||||||||||||||||||||||
| 262 | #ifndef NO_VALLOC | - | ||||||||||||||||||||||||
| 263 | static PTR_T internal_valloc __P((size_t, const char *, int, int)); | - | ||||||||||||||||||||||||
| 264 | #endif | - | ||||||||||||||||||||||||
| 265 | - | |||||||||||||||||||||||||
| 266 | #if defined (botch) | - | ||||||||||||||||||||||||
| 267 | extern void botch (); | - | ||||||||||||||||||||||||
| 268 | #else | - | ||||||||||||||||||||||||
| 269 | static void botch __P((const char *, const char *, int)); | - | ||||||||||||||||||||||||
| 270 | #endif | - | ||||||||||||||||||||||||
| 271 | static void xbotch __P((PTR_T, int, const char *, const char *, int)); | - | ||||||||||||||||||||||||
| 272 | - | |||||||||||||||||||||||||
| 273 | #if !HAVE_DECL_SBRK | - | ||||||||||||||||||||||||
| 274 | extern char *sbrk (); | - | ||||||||||||||||||||||||
| 275 | #endif /* !HAVE_DECL_SBRK */ | - | ||||||||||||||||||||||||
| 276 | - | |||||||||||||||||||||||||
| 277 | #ifdef SHELL | - | ||||||||||||||||||||||||
| 278 | extern int interrupt_immediately, running_trap; | - | ||||||||||||||||||||||||
| 279 | extern int signal_is_trapped __P((int)); | - | ||||||||||||||||||||||||
| 280 | #endif | - | ||||||||||||||||||||||||
| 281 | - | |||||||||||||||||||||||||
| 282 | #ifdef MALLOC_STATS | - | ||||||||||||||||||||||||
| 283 | struct _malstats _mstats; | - | ||||||||||||||||||||||||
| 284 | #endif /* MALLOC_STATS */ | - | ||||||||||||||||||||||||
| 285 | - | |||||||||||||||||||||||||
| 286 | /* Debugging variables available to applications. */ | - | ||||||||||||||||||||||||
| 287 | int malloc_flags = 0; /* future use */ | - | ||||||||||||||||||||||||
| 288 | int malloc_trace = 0; /* trace allocations and frees to stderr */ | - | ||||||||||||||||||||||||
| 289 | int malloc_register = 0; /* future use */ | - | ||||||||||||||||||||||||
| 290 | - | |||||||||||||||||||||||||
| 291 | #ifdef MALLOC_TRACE | - | ||||||||||||||||||||||||
| 292 | char _malloc_trace_buckets[NBUCKETS]; | - | ||||||||||||||||||||||||
| 293 | - | |||||||||||||||||||||||||
| 294 | /* These should really go into a header file. */ | - | ||||||||||||||||||||||||
| 295 | extern void mtrace_alloc __P((const char *, PTR_T, size_t, const char *, int)); | - | ||||||||||||||||||||||||
| 296 | extern void mtrace_free __P((PTR_T, int, const char *, int)); | - | ||||||||||||||||||||||||
| 297 | #endif | - | ||||||||||||||||||||||||
| 298 | - | |||||||||||||||||||||||||
| 299 | #if !defined (botch) | - | ||||||||||||||||||||||||
| 300 | static void | - | ||||||||||||||||||||||||
| 301 | botch (s, file, line) | - | ||||||||||||||||||||||||
| 302 | const char *s; | - | ||||||||||||||||||||||||
| 303 | const char *file; | - | ||||||||||||||||||||||||
| 304 | int line; | - | ||||||||||||||||||||||||
| 305 | { | - | ||||||||||||||||||||||||
| 306 | fprintf (stderr, _("malloc: failed assertion: %s\n"), s); | - | ||||||||||||||||||||||||
| 307 | (void)fflush (stderr); | - | ||||||||||||||||||||||||
| 308 | abort (); | - | ||||||||||||||||||||||||
| 309 | } | - | ||||||||||||||||||||||||
| 310 | #endif | - | ||||||||||||||||||||||||
| 311 | - | |||||||||||||||||||||||||
| 312 | /* print the file and line number that caused the assertion failure and | - | ||||||||||||||||||||||||
| 313 | call botch() to do whatever the application wants with the information */ | - | ||||||||||||||||||||||||
| 314 | static void | - | ||||||||||||||||||||||||
| 315 | xbotch (mem, e, s, file, line) | - | ||||||||||||||||||||||||
| 316 | PTR_T mem; | - | ||||||||||||||||||||||||
| 317 | int e; | - | ||||||||||||||||||||||||
| 318 | const char *s; | - | ||||||||||||||||||||||||
| 319 | const char *file; | - | ||||||||||||||||||||||||
| 320 | int line; | - | ||||||||||||||||||||||||
| 321 | { | - | ||||||||||||||||||||||||
| 322 | fprintf (stderr, _("\r\nmalloc: %s:%d: assertion botched\r\n"), | - | ||||||||||||||||||||||||
| 323 | file ? file : _("unknown"), line); | - | ||||||||||||||||||||||||
| 324 | #ifdef MALLOC_REGISTER | - | ||||||||||||||||||||||||
| 325 | if (mem != NULL && malloc_register)
| 0 | ||||||||||||||||||||||||
| 326 | mregister_describe_mem (mem, stderr); never executed: mregister_describe_mem (mem, stderr ); | 0 | ||||||||||||||||||||||||
| 327 | #endif | - | ||||||||||||||||||||||||
| 328 | (void)fflush (stderr); | - | ||||||||||||||||||||||||
| 329 | botch(s, file, line); | - | ||||||||||||||||||||||||
| 330 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 331 | - | |||||||||||||||||||||||||
| 332 | /* Coalesce two adjacent free blocks off the free list for size NU - 1, | - | ||||||||||||||||||||||||
| 333 | as long as we can find two adjacent free blocks. nextf[NU -1] is | - | ||||||||||||||||||||||||
| 334 | assumed to not be busy; the caller (morecore()) checks for this. | - | ||||||||||||||||||||||||
| 335 | BUSY[NU] must be set to 1. */ | - | ||||||||||||||||||||||||
| 336 | static void | - | ||||||||||||||||||||||||
| 337 | bcoalesce (nu) | - | ||||||||||||||||||||||||
| 338 | register int nu; | - | ||||||||||||||||||||||||
| 339 | { | - | ||||||||||||||||||||||||
| 340 | register union mhead *mp, *mp1, *mp2; | - | ||||||||||||||||||||||||
| 341 | register int nbuck; | - | ||||||||||||||||||||||||
| 342 | unsigned long siz; | - | ||||||||||||||||||||||||
| 343 | - | |||||||||||||||||||||||||
| 344 | nbuck = nu - 1; | - | ||||||||||||||||||||||||
| 345 | if (nextf[nbuck] == 0 || busy[nbuck])
| 0-189187 | ||||||||||||||||||||||||
| 346 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 347 | - | |||||||||||||||||||||||||
| 348 | busy[nbuck] = 1; | - | ||||||||||||||||||||||||
| 349 | siz = binsize (nbuck); | - | ||||||||||||||||||||||||
| 350 | - | |||||||||||||||||||||||||
| 351 | mp2 = mp1 = nextf[nbuck]; | - | ||||||||||||||||||||||||
| 352 | mp = CHAIN (mp1); | - | ||||||||||||||||||||||||
| 353 | while (mp && mp != (union mhead *)((char *)mp1 + siz))
| 24071-337004 | ||||||||||||||||||||||||
| 354 | { | - | ||||||||||||||||||||||||
| 355 | mp2 = mp1; | - | ||||||||||||||||||||||||
| 356 | mp1 = mp; | - | ||||||||||||||||||||||||
| 357 | mp = CHAIN (mp); | - | ||||||||||||||||||||||||
| 358 | } executed 171888 times by 1 test: end of blockExecuted by:
| 171888 | ||||||||||||||||||||||||
| 359 | - | |||||||||||||||||||||||||
| 360 | if (mp == 0)
| 24071-165116 | ||||||||||||||||||||||||
| 361 | { | - | ||||||||||||||||||||||||
| 362 | busy[nbuck] = 0; | - | ||||||||||||||||||||||||
| 363 | return; executed 24071 times by 1 test: return;Executed by:
| 24071 | ||||||||||||||||||||||||
| 364 | } | - | ||||||||||||||||||||||||
| 365 | - | |||||||||||||||||||||||||
| 366 | /* OK, now we have mp1 pointing to the block we want to add to nextf[NU]. | - | ||||||||||||||||||||||||
| 367 | CHAIN(mp2) must equal mp1. Check that mp1 and mp are adjacent. */ | - | ||||||||||||||||||||||||
| 368 | if (mp2 != mp1 && CHAIN(mp2) != mp1)
| 0-128147 | ||||||||||||||||||||||||
| 369 | { | - | ||||||||||||||||||||||||
| 370 | busy[nbuck] = 0; | - | ||||||||||||||||||||||||
| 371 | xbotch ((PTR_T)0, 0, "bcoalesce: CHAIN(mp2) != mp1", (char *)NULL, 0); | - | ||||||||||||||||||||||||
| 372 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 373 | - | |||||||||||||||||||||||||
| 374 | #ifdef MALLOC_DEBUG | - | ||||||||||||||||||||||||
| 375 | if (CHAIN (mp1) != (union mhead *)((char *)mp1 + siz))
| 0-165116 | ||||||||||||||||||||||||
| 376 | { | - | ||||||||||||||||||||||||
| 377 | busy[nbuck] = 0; | - | ||||||||||||||||||||||||
| 378 | return; /* not adjacent */ never executed: return; | 0 | ||||||||||||||||||||||||
| 379 | } | - | ||||||||||||||||||||||||
| 380 | #endif | - | ||||||||||||||||||||||||
| 381 | - | |||||||||||||||||||||||||
| 382 | /* Since they are adjacent, remove them from the free list */ | - | ||||||||||||||||||||||||
| 383 | if (mp1 == nextf[nbuck])
| 36969-128147 | ||||||||||||||||||||||||
| 384 | nextf[nbuck] = CHAIN (mp); executed 128147 times by 1 test: nextf[nbuck] = (*(union mhead **) (sizeof (char *) + (char *) (mp)));Executed by:
| 128147 | ||||||||||||||||||||||||
| 385 | else | - | ||||||||||||||||||||||||
| 386 | CHAIN (mp2) = CHAIN (mp); executed 36969 times by 1 test: (*(union mhead **) (sizeof (char *) + (char *) (mp2))) = (*(union mhead **) (sizeof (char *) + (char *) (mp)));Executed by:
| 36969 | ||||||||||||||||||||||||
| 387 | busy[nbuck] = 0; | - | ||||||||||||||||||||||||
| 388 | - | |||||||||||||||||||||||||
| 389 | #ifdef MALLOC_STATS | - | ||||||||||||||||||||||||
| 390 | _mstats.tbcoalesce++; | - | ||||||||||||||||||||||||
| 391 | _mstats.ncoalesce[nbuck]++; | - | ||||||||||||||||||||||||
| 392 | #endif | - | ||||||||||||||||||||||||
| 393 | - | |||||||||||||||||||||||||
| 394 | /* And add the combined two blocks to nextf[NU]. */ | - | ||||||||||||||||||||||||
| 395 | mp1->mh_alloc = ISFREE; | - | ||||||||||||||||||||||||
| 396 | mp1->mh_index = nu; | - | ||||||||||||||||||||||||
| 397 | CHAIN (mp1) = nextf[nu]; | - | ||||||||||||||||||||||||
| 398 | nextf[nu] = mp1; | - | ||||||||||||||||||||||||
| 399 | } executed 165116 times by 1 test: end of blockExecuted by:
| 165116 | ||||||||||||||||||||||||
| 400 | - | |||||||||||||||||||||||||
| 401 | /* Split a block at index > NU (but less than SPLIT_MAX) into a set of | - | ||||||||||||||||||||||||
| 402 | blocks of the correct size, and attach them to nextf[NU]. nextf[NU] | - | ||||||||||||||||||||||||
| 403 | is assumed to be empty. Must be called with signals blocked (e.g., | - | ||||||||||||||||||||||||
| 404 | by morecore()). BUSY[NU] must be set to 1. */ | - | ||||||||||||||||||||||||
| 405 | static void | - | ||||||||||||||||||||||||
| 406 | bsplit (nu) | - | ||||||||||||||||||||||||
| 407 | register int nu; | - | ||||||||||||||||||||||||
| 408 | { | - | ||||||||||||||||||||||||
| 409 | register union mhead *mp; | - | ||||||||||||||||||||||||
| 410 | int nbuck, nblks, split_max; | - | ||||||||||||||||||||||||
| 411 | unsigned long siz; | - | ||||||||||||||||||||||||
| 412 | - | |||||||||||||||||||||||||
| 413 | split_max = (maxbuck > SPLIT_MAX) ? maxbuck : SPLIT_MAX;
| 203279-2975467 | ||||||||||||||||||||||||
| 414 | - | |||||||||||||||||||||||||
| 415 | if (nu >= SPLIT_MID)
| 13786-3164960 | ||||||||||||||||||||||||
| 416 | { | - | ||||||||||||||||||||||||
| 417 | for (nbuck = split_max; nbuck > nu; nbuck--)
| 13776-25847 | ||||||||||||||||||||||||
| 418 | { | - | ||||||||||||||||||||||||
| 419 | if (busy[nbuck] || nextf[nbuck] == 0)
| 0-25847 | ||||||||||||||||||||||||
| 420 | continue; executed 25837 times by 1 test: continue;Executed by:
| 25837 | ||||||||||||||||||||||||
| 421 | break; executed 10 times by 1 test: break;Executed by:
| 10 | ||||||||||||||||||||||||
| 422 | } | - | ||||||||||||||||||||||||
| 423 | } executed 13786 times by 1 test: end of blockExecuted by:
| 13786 | ||||||||||||||||||||||||
| 424 | else | - | ||||||||||||||||||||||||
| 425 | { | - | ||||||||||||||||||||||||
| 426 | for (nbuck = nu + 1; nbuck <= split_max; nbuck++)
| 329326-6486574 | ||||||||||||||||||||||||
| 427 | { | - | ||||||||||||||||||||||||
| 428 | if (busy[nbuck] || nextf[nbuck] == 0)
| 0-6486574 | ||||||||||||||||||||||||
| 429 | continue; executed 3650940 times by 1 test: continue;Executed by:
| 3650940 | ||||||||||||||||||||||||
| 430 | break; executed 2835634 times by 1 test: break;Executed by:
| 2835634 | ||||||||||||||||||||||||
| 431 | } | - | ||||||||||||||||||||||||
| 432 | } executed 3164960 times by 1 test: end of blockExecuted by:
| 3164960 | ||||||||||||||||||||||||
| 433 | - | |||||||||||||||||||||||||
| 434 | if (nbuck > split_max || nbuck <= nu)
| 13776-2849420 | ||||||||||||||||||||||||
| 435 | return; executed 343102 times by 1 test: return;Executed by:
| 343102 | ||||||||||||||||||||||||
| 436 | - | |||||||||||||||||||||||||
| 437 | /* XXX might want to split only if nextf[nbuck] has >= 2 blocks free | - | ||||||||||||||||||||||||
| 438 | and nbuck is below some threshold. */ | - | ||||||||||||||||||||||||
| 439 | - | |||||||||||||||||||||||||
| 440 | /* Remove the block from the chain of larger blocks. */ | - | ||||||||||||||||||||||||
| 441 | busy[nbuck] = 1; | - | ||||||||||||||||||||||||
| 442 | mp = nextf[nbuck]; | - | ||||||||||||||||||||||||
| 443 | nextf[nbuck] = CHAIN (mp); | - | ||||||||||||||||||||||||
| 444 | busy[nbuck] = 0; | - | ||||||||||||||||||||||||
| 445 | - | |||||||||||||||||||||||||
| 446 | #ifdef MALLOC_STATS | - | ||||||||||||||||||||||||
| 447 | _mstats.tbsplit++; | - | ||||||||||||||||||||||||
| 448 | _mstats.nsplit[nbuck]++; | - | ||||||||||||||||||||||||
| 449 | #endif | - | ||||||||||||||||||||||||
| 450 | - | |||||||||||||||||||||||||
| 451 | /* Figure out how many blocks we'll get. */ | - | ||||||||||||||||||||||||
| 452 | siz = binsize (nu); | - | ||||||||||||||||||||||||
| 453 | nblks = binsize (nbuck) / siz; | - | ||||||||||||||||||||||||
| 454 | - | |||||||||||||||||||||||||
| 455 | /* Split the block and put it on the requested chain. */ | - | ||||||||||||||||||||||||
| 456 | nextf[nu] = mp; | - | ||||||||||||||||||||||||
| 457 | while (1) | - | ||||||||||||||||||||||||
| 458 | { | - | ||||||||||||||||||||||||
| 459 | mp->mh_alloc = ISFREE; | - | ||||||||||||||||||||||||
| 460 | mp->mh_index = nu; | - | ||||||||||||||||||||||||
| 461 | if (--nblks <= 0) break; executed 2835644 times by 1 test: break;Executed by:
| 2835644-4839142 | ||||||||||||||||||||||||
| 462 | CHAIN (mp) = (union mhead *)((char *)mp + siz); | - | ||||||||||||||||||||||||
| 463 | mp = (union mhead *)((char *)mp + siz); | - | ||||||||||||||||||||||||
| 464 | } executed 4839142 times by 1 test: end of blockExecuted by:
| 4839142 | ||||||||||||||||||||||||
| 465 | CHAIN (mp) = 0; | - | ||||||||||||||||||||||||
| 466 | } executed 2835644 times by 1 test: end of blockExecuted by:
| 2835644 | ||||||||||||||||||||||||
| 467 | - | |||||||||||||||||||||||||
| 468 | /* Take the memory block MP and add it to a chain < NU. NU is the right bucket, | - | ||||||||||||||||||||||||
| 469 | but is busy. This avoids memory orphaning. */ | - | ||||||||||||||||||||||||
| 470 | static void | - | ||||||||||||||||||||||||
| 471 | xsplit (mp, nu) | - | ||||||||||||||||||||||||
| 472 | union mhead *mp; | - | ||||||||||||||||||||||||
| 473 | int nu; | - | ||||||||||||||||||||||||
| 474 | { | - | ||||||||||||||||||||||||
| 475 | union mhead *nh; | - | ||||||||||||||||||||||||
| 476 | int nbuck, nblks, split_max; | - | ||||||||||||||||||||||||
| 477 | unsigned long siz; | - | ||||||||||||||||||||||||
| 478 | - | |||||||||||||||||||||||||
| 479 | nbuck = nu - 1; | - | ||||||||||||||||||||||||
| 480 | while (nbuck >= SPLIT_MIN && busy[nbuck])
| 0 | ||||||||||||||||||||||||
| 481 | nbuck--; never executed: nbuck--; | 0 | ||||||||||||||||||||||||
| 482 | if (nbuck < SPLIT_MIN)
| 0 | ||||||||||||||||||||||||
| 483 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 484 | - | |||||||||||||||||||||||||
| 485 | #ifdef MALLOC_STATS | - | ||||||||||||||||||||||||
| 486 | _mstats.tbsplit++; | - | ||||||||||||||||||||||||
| 487 | _mstats.nsplit[nu]++; | - | ||||||||||||||||||||||||
| 488 | #endif | - | ||||||||||||||||||||||||
| 489 | - | |||||||||||||||||||||||||
| 490 | /* Figure out how many blocks we'll get. */ | - | ||||||||||||||||||||||||
| 491 | siz = binsize (nu); /* original block size */ | - | ||||||||||||||||||||||||
| 492 | nblks = siz / binsize (nbuck); /* should be 2 most of the time */ | - | ||||||||||||||||||||||||
| 493 | - | |||||||||||||||||||||||||
| 494 | /* And add it to nextf[nbuck] */ | - | ||||||||||||||||||||||||
| 495 | siz = binsize (nbuck); /* XXX - resetting here */ | - | ||||||||||||||||||||||||
| 496 | nh = mp; | - | ||||||||||||||||||||||||
| 497 | while (1) | - | ||||||||||||||||||||||||
| 498 | { | - | ||||||||||||||||||||||||
| 499 | mp->mh_alloc = ISFREE; | - | ||||||||||||||||||||||||
| 500 | mp->mh_index = nbuck; | - | ||||||||||||||||||||||||
| 501 | if (--nblks <= 0) break; never executed: break;
| 0 | ||||||||||||||||||||||||
| 502 | CHAIN (mp) = (union mhead *)((char *)mp + siz); | - | ||||||||||||||||||||||||
| 503 | mp = (union mhead *)((char *)mp + siz); | - | ||||||||||||||||||||||||
| 504 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 505 | busy[nbuck] = 1; | - | ||||||||||||||||||||||||
| 506 | CHAIN (mp) = nextf[nbuck]; | - | ||||||||||||||||||||||||
| 507 | nextf[nbuck] = nh; | - | ||||||||||||||||||||||||
| 508 | busy[nbuck] = 0; | - | ||||||||||||||||||||||||
| 509 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 510 | - | |||||||||||||||||||||||||
| 511 | void | - | ||||||||||||||||||||||||
| 512 | _malloc_block_signals (setp, osetp) | - | ||||||||||||||||||||||||
| 513 | sigset_t *setp, *osetp; | - | ||||||||||||||||||||||||
| 514 | { | - | ||||||||||||||||||||||||
| 515 | #ifdef HAVE_POSIX_SIGNALS | - | ||||||||||||||||||||||||
| 516 | sigfillset (setp); | - | ||||||||||||||||||||||||
| 517 | sigemptyset (osetp); | - | ||||||||||||||||||||||||
| 518 | sigprocmask (SIG_BLOCK, setp, osetp); | - | ||||||||||||||||||||||||
| 519 | #else | - | ||||||||||||||||||||||||
| 520 | # if defined (HAVE_BSD_SIGNALS) | - | ||||||||||||||||||||||||
| 521 | *osetp = sigsetmask (-1); | - | ||||||||||||||||||||||||
| 522 | # endif | - | ||||||||||||||||||||||||
| 523 | #endif | - | ||||||||||||||||||||||||
| 524 | } executed 627432 times by 1 test: end of blockExecuted by:
| 627432 | ||||||||||||||||||||||||
| 525 | - | |||||||||||||||||||||||||
| 526 | void | - | ||||||||||||||||||||||||
| 527 | _malloc_unblock_signals (setp, osetp) | - | ||||||||||||||||||||||||
| 528 | sigset_t *setp, *osetp; | - | ||||||||||||||||||||||||
| 529 | { | - | ||||||||||||||||||||||||
| 530 | #ifdef HAVE_POSIX_SIGNALS | - | ||||||||||||||||||||||||
| 531 | sigprocmask (SIG_SETMASK, osetp, (sigset_t *)NULL); | - | ||||||||||||||||||||||||
| 532 | #else | - | ||||||||||||||||||||||||
| 533 | # if defined (HAVE_BSD_SIGNALS) | - | ||||||||||||||||||||||||
| 534 | sigsetmask (*osetp); | - | ||||||||||||||||||||||||
| 535 | # endif | - | ||||||||||||||||||||||||
| 536 | #endif | - | ||||||||||||||||||||||||
| 537 | } executed 627432 times by 1 test: end of blockExecuted by:
| 627432 | ||||||||||||||||||||||||
| 538 | - | |||||||||||||||||||||||||
| 539 | /* Return some memory to the system by reducing the break. This is only | - | ||||||||||||||||||||||||
| 540 | called with NU > pagebucket, so we're always assured of giving back | - | ||||||||||||||||||||||||
| 541 | more than one page of memory. */ | - | ||||||||||||||||||||||||
| 542 | static void | - | ||||||||||||||||||||||||
| 543 | lesscore (nu) /* give system back some memory */ | - | ||||||||||||||||||||||||
| 544 | register int nu; /* size index we're discarding */ | - | ||||||||||||||||||||||||
| 545 | { | - | ||||||||||||||||||||||||
| 546 | long siz; | - | ||||||||||||||||||||||||
| 547 | - | |||||||||||||||||||||||||
| 548 | siz = binsize (nu); | - | ||||||||||||||||||||||||
| 549 | /* Should check for errors here, I guess. */ | - | ||||||||||||||||||||||||
| 550 | sbrk (-siz); | - | ||||||||||||||||||||||||
| 551 | memtop -= siz; | - | ||||||||||||||||||||||||
| 552 | - | |||||||||||||||||||||||||
| 553 | #ifdef MALLOC_STATS | - | ||||||||||||||||||||||||
| 554 | _mstats.nsbrk++; | - | ||||||||||||||||||||||||
| 555 | _mstats.tsbrk -= siz; | - | ||||||||||||||||||||||||
| 556 | _mstats.nlesscore[nu]++; | - | ||||||||||||||||||||||||
| 557 | #endif | - | ||||||||||||||||||||||||
| 558 | } executed 1722 times by 1 test: end of blockExecuted by:
| 1722 | ||||||||||||||||||||||||
| 559 | - | |||||||||||||||||||||||||
| 560 | /* Ask system for more memory; add to NEXTF[NU]. BUSY[NU] must be set to 1. */ | - | ||||||||||||||||||||||||
| 561 | static void | - | ||||||||||||||||||||||||
| 562 | morecore (nu) | - | ||||||||||||||||||||||||
| 563 | register int nu; /* size index to get more of */ | - | ||||||||||||||||||||||||
| 564 | { | - | ||||||||||||||||||||||||
| 565 | register union mhead *mp; | - | ||||||||||||||||||||||||
| 566 | register int nblks; | - | ||||||||||||||||||||||||
| 567 | register long siz; | - | ||||||||||||||||||||||||
| 568 | long sbrk_amt; /* amount to get via sbrk() */ | - | ||||||||||||||||||||||||
| 569 | sigset_t set, oset; | - | ||||||||||||||||||||||||
| 570 | int blocked_sigs; | - | ||||||||||||||||||||||||
| 571 | - | |||||||||||||||||||||||||
| 572 | /* Block all signals in case we are executed from a signal handler. */ | - | ||||||||||||||||||||||||
| 573 | blocked_sigs = 0; | - | ||||||||||||||||||||||||
| 574 | #ifdef SHELL | - | ||||||||||||||||||||||||
| 575 | # if defined (SIGCHLD) | - | ||||||||||||||||||||||||
| 576 | if (interrupt_immediately || running_trap || signal_is_trapped (SIGINT) || signal_is_trapped (SIGCHLD))
| 0-3186477 | ||||||||||||||||||||||||
| 577 | # else | - | ||||||||||||||||||||||||
| 578 | if (interrupt_immediately || running_trap || signal_is_trapped (SIGINT)) | - | ||||||||||||||||||||||||
| 579 | # endif | - | ||||||||||||||||||||||||
| 580 | #endif | - | ||||||||||||||||||||||||
| 581 | { | - | ||||||||||||||||||||||||
| 582 | _malloc_block_signals (&set, &oset); | - | ||||||||||||||||||||||||
| 583 | blocked_sigs = 1; | - | ||||||||||||||||||||||||
| 584 | } executed 5197 times by 1 test: end of blockExecuted by:
| 5197 | ||||||||||||||||||||||||
| 585 | - | |||||||||||||||||||||||||
| 586 | siz = binsize (nu); /* size of desired block for nextf[nu] */ | - | ||||||||||||||||||||||||
| 587 | - | |||||||||||||||||||||||||
| 588 | if (siz < 0)
| 0-3186477 | ||||||||||||||||||||||||
| 589 | goto morecore_done; /* oops */ never executed: goto morecore_done; | 0 | ||||||||||||||||||||||||
| 590 | - | |||||||||||||||||||||||||
| 591 | #ifdef MALLOC_STATS | - | ||||||||||||||||||||||||
| 592 | _mstats.nmorecore[nu]++; | - | ||||||||||||||||||||||||
| 593 | #endif | - | ||||||||||||||||||||||||
| 594 | - | |||||||||||||||||||||||||
| 595 | /* Try to split a larger block here, if we're within the range of sizes | - | ||||||||||||||||||||||||
| 596 | to split. */ | - | ||||||||||||||||||||||||
| 597 | if (nu >= SPLIT_MIN)
| 7731-3178746 | ||||||||||||||||||||||||
| 598 | { | - | ||||||||||||||||||||||||
| 599 | bsplit (nu); | - | ||||||||||||||||||||||||
| 600 | if (nextf[nu] != 0)
| 343102-2835644 | ||||||||||||||||||||||||
| 601 | goto morecore_done; executed 2835644 times by 1 test: goto morecore_done;Executed by:
| 2835644 | ||||||||||||||||||||||||
| 602 | } executed 343102 times by 1 test: end of blockExecuted by:
| 343102 | ||||||||||||||||||||||||
| 603 | - | |||||||||||||||||||||||||
| 604 | /* Try to coalesce two adjacent blocks from the free list on nextf[nu - 1], | - | ||||||||||||||||||||||||
| 605 | if we can, and we're within the range of the block coalescing limits. */ | - | ||||||||||||||||||||||||
| 606 | if (nu >= COMBINE_MIN && nu < COMBINE_MAX && busy[nu - 1] == 0 && nextf[nu - 1])
| 0-343102 | ||||||||||||||||||||||||
| 607 | { | - | ||||||||||||||||||||||||
| 608 | bcoalesce (nu); | - | ||||||||||||||||||||||||
| 609 | if (nextf[nu] != 0)
| 24071-165116 | ||||||||||||||||||||||||
| 610 | goto morecore_done; executed 165116 times by 1 test: goto morecore_done;Executed by:
| 165116 | ||||||||||||||||||||||||
| 611 | } executed 24071 times by 1 test: end of blockExecuted by:
| 24071 | ||||||||||||||||||||||||
| 612 | - | |||||||||||||||||||||||||
| 613 | /* Take at least a page, and figure out how many blocks of the requested | - | ||||||||||||||||||||||||
| 614 | size we're getting. */ | - | ||||||||||||||||||||||||
| 615 | if (siz <= pagesz)
| 37908-147809 | ||||||||||||||||||||||||
| 616 | { | - | ||||||||||||||||||||||||
| 617 | sbrk_amt = pagesz; | - | ||||||||||||||||||||||||
| 618 | nblks = sbrk_amt / siz; | - | ||||||||||||||||||||||||
| 619 | } executed 147809 times by 1 test: end of blockExecuted by:
| 147809 | ||||||||||||||||||||||||
| 620 | else | - | ||||||||||||||||||||||||
| 621 | { | - | ||||||||||||||||||||||||
| 622 | /* We always want to request an integral multiple of the page size | - | ||||||||||||||||||||||||
| 623 | from the kernel, so let's compute whether or not `siz' is such | - | ||||||||||||||||||||||||
| 624 | an amount. If it is, we can just request it. If not, we want | - | ||||||||||||||||||||||||
| 625 | the smallest integral multiple of pagesize that is larger than | - | ||||||||||||||||||||||||
| 626 | `siz' and will satisfy the request. */ | - | ||||||||||||||||||||||||
| 627 | sbrk_amt = siz & (pagesz - 1); | - | ||||||||||||||||||||||||
| 628 | if (sbrk_amt == 0)
| 0-37908 | ||||||||||||||||||||||||
| 629 | sbrk_amt = siz; executed 37908 times by 1 test: sbrk_amt = siz;Executed by:
| 37908 | ||||||||||||||||||||||||
| 630 | else | - | ||||||||||||||||||||||||
| 631 | sbrk_amt = siz + pagesz - sbrk_amt; never executed: sbrk_amt = siz + pagesz - sbrk_amt; | 0 | ||||||||||||||||||||||||
| 632 | nblks = 1; | - | ||||||||||||||||||||||||
| 633 | } executed 37908 times by 1 test: end of blockExecuted by:
| 37908 | ||||||||||||||||||||||||
| 634 | - | |||||||||||||||||||||||||
| 635 | #ifdef MALLOC_STATS | - | ||||||||||||||||||||||||
| 636 | _mstats.nsbrk++; | - | ||||||||||||||||||||||||
| 637 | _mstats.tsbrk += sbrk_amt; | - | ||||||||||||||||||||||||
| 638 | #endif | - | ||||||||||||||||||||||||
| 639 | - | |||||||||||||||||||||||||
| 640 | mp = (union mhead *) sbrk (sbrk_amt); | - | ||||||||||||||||||||||||
| 641 | - | |||||||||||||||||||||||||
| 642 | /* Totally out of memory. */ | - | ||||||||||||||||||||||||
| 643 | if ((long)mp == -1)
| 0-185717 | ||||||||||||||||||||||||
| 644 | goto morecore_done; never executed: goto morecore_done; | 0 | ||||||||||||||||||||||||
| 645 | - | |||||||||||||||||||||||||
| 646 | memtop += sbrk_amt; | - | ||||||||||||||||||||||||
| 647 | - | |||||||||||||||||||||||||
| 648 | /* shouldn't happen, but just in case -- require 8-byte alignment */ | - | ||||||||||||||||||||||||
| 649 | if ((long)mp & MALIGN_MASK)
| 0-185717 | ||||||||||||||||||||||||
| 650 | { | - | ||||||||||||||||||||||||
| 651 | mp = (union mhead *) (((long)mp + MALIGN_MASK) & ~MALIGN_MASK); | - | ||||||||||||||||||||||||
| 652 | nblks--; | - | ||||||||||||||||||||||||
| 653 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 654 | - | |||||||||||||||||||||||||
| 655 | /* save new header and link the nblks blocks together */ | - | ||||||||||||||||||||||||
| 656 | nextf[nu] = mp; | - | ||||||||||||||||||||||||
| 657 | while (1) | - | ||||||||||||||||||||||||
| 658 | { | - | ||||||||||||||||||||||||
| 659 | mp->mh_alloc = ISFREE; | - | ||||||||||||||||||||||||
| 660 | mp->mh_index = nu; | - | ||||||||||||||||||||||||
| 661 | if (--nblks <= 0) break; executed 185717 times by 1 test: break;Executed by:
| 185717-6130904 | ||||||||||||||||||||||||
| 662 | CHAIN (mp) = (union mhead *)((char *)mp + siz); | - | ||||||||||||||||||||||||
| 663 | mp = (union mhead *)((char *)mp + siz); | - | ||||||||||||||||||||||||
| 664 | } executed 6130904 times by 1 test: end of blockExecuted by:
| 6130904 | ||||||||||||||||||||||||
| 665 | CHAIN (mp) = 0; | - | ||||||||||||||||||||||||
| 666 | - | |||||||||||||||||||||||||
| 667 | morecore_done: code before this statement executed 185717 times by 1 test: morecore_done:Executed by:
| 185717 | ||||||||||||||||||||||||
| 668 | if (blocked_sigs)
| 5197-3181280 | ||||||||||||||||||||||||
| 669 | _malloc_unblock_signals (&set, &oset); executed 5197 times by 1 test: _malloc_unblock_signals (&set, &oset);Executed by:
| 5197 | ||||||||||||||||||||||||
| 670 | } executed 3186477 times by 1 test: end of blockExecuted by:
| 3186477 | ||||||||||||||||||||||||
| 671 | - | |||||||||||||||||||||||||
| 672 | static void | - | ||||||||||||||||||||||||
| 673 | malloc_debug_dummy () | - | ||||||||||||||||||||||||
| 674 | { | - | ||||||||||||||||||||||||
| 675 | write (1, "malloc_debug_dummy\n", 19); | - | ||||||||||||||||||||||||
| 676 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 677 | - | |||||||||||||||||||||||||
| 678 | #define PREPOP_BIN 2 | - | ||||||||||||||||||||||||
| 679 | #define PREPOP_SIZE 32 | - | ||||||||||||||||||||||||
| 680 | - | |||||||||||||||||||||||||
| 681 | static int | - | ||||||||||||||||||||||||
| 682 | pagealign () | - | ||||||||||||||||||||||||
| 683 | { | - | ||||||||||||||||||||||||
| 684 | register int nunits; | - | ||||||||||||||||||||||||
| 685 | register union mhead *mp; | - | ||||||||||||||||||||||||
| 686 | long sbrk_needed; | - | ||||||||||||||||||||||||
| 687 | char *curbrk; | - | ||||||||||||||||||||||||
| 688 | - | |||||||||||||||||||||||||
| 689 | pagesz = getpagesize (); | - | ||||||||||||||||||||||||
| 690 | if (pagesz < 1024)
| 0-5432 | ||||||||||||||||||||||||
| 691 | pagesz = 1024; never executed: pagesz = 1024; | 0 | ||||||||||||||||||||||||
| 692 | - | |||||||||||||||||||||||||
| 693 | /* OK, how much do we need to allocate to make things page-aligned? | - | ||||||||||||||||||||||||
| 694 | Some of this partial page will be wasted space, but we'll use as | - | ||||||||||||||||||||||||
| 695 | much as we can. Once we figure out how much to advance the break | - | ||||||||||||||||||||||||
| 696 | pointer, go ahead and do it. */ | - | ||||||||||||||||||||||||
| 697 | memtop = curbrk = sbrk (0); | - | ||||||||||||||||||||||||
| 698 | sbrk_needed = pagesz - ((long)curbrk & (pagesz - 1)); /* sbrk(0) % pagesz */ | - | ||||||||||||||||||||||||
| 699 | if (sbrk_needed < 0)
| 0-5432 | ||||||||||||||||||||||||
| 700 | sbrk_needed += pagesz; never executed: sbrk_needed += pagesz; | 0 | ||||||||||||||||||||||||
| 701 | - | |||||||||||||||||||||||||
| 702 | /* Now allocate the wasted space. */ | - | ||||||||||||||||||||||||
| 703 | if (sbrk_needed)
| 0-5432 | ||||||||||||||||||||||||
| 704 | { | - | ||||||||||||||||||||||||
| 705 | #ifdef MALLOC_STATS | - | ||||||||||||||||||||||||
| 706 | _mstats.nsbrk++; | - | ||||||||||||||||||||||||
| 707 | _mstats.tsbrk += sbrk_needed; | - | ||||||||||||||||||||||||
| 708 | #endif | - | ||||||||||||||||||||||||
| 709 | curbrk = sbrk (sbrk_needed); | - | ||||||||||||||||||||||||
| 710 | if ((long)curbrk == -1)
| 0-5432 | ||||||||||||||||||||||||
| 711 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
| 712 | memtop += sbrk_needed; | - | ||||||||||||||||||||||||
| 713 | - | |||||||||||||||||||||||||
| 714 | /* Take the memory which would otherwise be wasted and populate the most | - | ||||||||||||||||||||||||
| 715 | popular bin (2 == 32 bytes) with it. Add whatever we need to curbrk | - | ||||||||||||||||||||||||
| 716 | to make things 32-byte aligned, compute how many 32-byte chunks we're | - | ||||||||||||||||||||||||
| 717 | going to get, and set up the bin. */ | - | ||||||||||||||||||||||||
| 718 | curbrk += sbrk_needed & (PREPOP_SIZE - 1); | - | ||||||||||||||||||||||||
| 719 | sbrk_needed -= sbrk_needed & (PREPOP_SIZE - 1); | - | ||||||||||||||||||||||||
| 720 | nunits = sbrk_needed / PREPOP_SIZE; | - | ||||||||||||||||||||||||
| 721 | - | |||||||||||||||||||||||||
| 722 | if (nunits > 0)
| 0-5432 | ||||||||||||||||||||||||
| 723 | { | - | ||||||||||||||||||||||||
| 724 | mp = (union mhead *)curbrk; | - | ||||||||||||||||||||||||
| 725 | - | |||||||||||||||||||||||||
| 726 | nextf[PREPOP_BIN] = mp; | - | ||||||||||||||||||||||||
| 727 | while (1) | - | ||||||||||||||||||||||||
| 728 | { | - | ||||||||||||||||||||||||
| 729 | mp->mh_alloc = ISFREE; | - | ||||||||||||||||||||||||
| 730 | mp->mh_index = PREPOP_BIN; | - | ||||||||||||||||||||||||
| 731 | if (--nunits <= 0) break; executed 5432 times by 1 test: break;Executed by:
| 5432-689864 | ||||||||||||||||||||||||
| 732 | CHAIN(mp) = (union mhead *)((char *)mp + PREPOP_SIZE); | - | ||||||||||||||||||||||||
| 733 | mp = (union mhead *)((char *)mp + PREPOP_SIZE); | - | ||||||||||||||||||||||||
| 734 | } executed 689864 times by 1 test: end of blockExecuted by:
| 689864 | ||||||||||||||||||||||||
| 735 | CHAIN(mp) = 0; | - | ||||||||||||||||||||||||
| 736 | } executed 5432 times by 1 test: end of blockExecuted by:
| 5432 | ||||||||||||||||||||||||
| 737 | } executed 5432 times by 1 test: end of blockExecuted by:
| 5432 | ||||||||||||||||||||||||
| 738 | - | |||||||||||||||||||||||||
| 739 | /* compute which bin corresponds to the page size. */ | - | ||||||||||||||||||||||||
| 740 | for (nunits = 7; nunits < NBUCKETS; nunits++)
| 0-16296 | ||||||||||||||||||||||||
| 741 | if (pagesz <= binsize(nunits))
| 5432-10864 | ||||||||||||||||||||||||
| 742 | break; executed 5432 times by 1 test: break;Executed by:
| 5432 | ||||||||||||||||||||||||
| 743 | pagebucket = nunits; | - | ||||||||||||||||||||||||
| 744 | - | |||||||||||||||||||||||||
| 745 | return 0; executed 5432 times by 1 test: return 0;Executed by:
| 5432 | ||||||||||||||||||||||||
| 746 | } | - | ||||||||||||||||||||||||
| 747 | - | |||||||||||||||||||||||||
| 748 | static PTR_T | - | ||||||||||||||||||||||||
| 749 | internal_malloc (n, file, line, flags) /* get a block */ | - | ||||||||||||||||||||||||
| 750 | size_t n; | - | ||||||||||||||||||||||||
| 751 | const char *file; | - | ||||||||||||||||||||||||
| 752 | int line, flags; | - | ||||||||||||||||||||||||
| 753 | { | - | ||||||||||||||||||||||||
| 754 | register union mhead *p; | - | ||||||||||||||||||||||||
| 755 | register int nunits; | - | ||||||||||||||||||||||||
| 756 | register char *m, *z; | - | ||||||||||||||||||||||||
| 757 | long nbytes; | - | ||||||||||||||||||||||||
| 758 | mguard_t mg; | - | ||||||||||||||||||||||||
| 759 | - | |||||||||||||||||||||||||
| 760 | /* Get the system page size and align break pointer so future sbrks will | - | ||||||||||||||||||||||||
| 761 | be page-aligned. The page size must be at least 1K -- anything | - | ||||||||||||||||||||||||
| 762 | smaller is increased. */ | - | ||||||||||||||||||||||||
| 763 | if (pagesz == 0)
| 5432-Inf | ||||||||||||||||||||||||
| 764 | if (pagealign () < 0)
| 0-5432 | ||||||||||||||||||||||||
| 765 | return ((PTR_T)NULL); never executed: return ((void *) ((void *)0) ); | 0 | ||||||||||||||||||||||||
| 766 | - | |||||||||||||||||||||||||
| 767 | /* Figure out how many bytes are required, rounding up to the nearest | - | ||||||||||||||||||||||||
| 768 | multiple of 8, then figure out which nextf[] area to use. Try to | - | ||||||||||||||||||||||||
| 769 | be smart about where to start searching -- if the number of bytes | - | ||||||||||||||||||||||||
| 770 | needed is greater than the page size, we can start at pagebucket. */ | - | ||||||||||||||||||||||||
| 771 | nbytes = ALLOCATED_BYTES(n); | - | ||||||||||||||||||||||||
| 772 | nunits = (nbytes <= (pagesz >> 1)) ? STARTBUCK : pagebucket;
| 57895586-Inf | ||||||||||||||||||||||||
| 773 | for ( ; nunits < NBUCKETS; nunits++)
| 0-Inf | ||||||||||||||||||||||||
| 774 | if (nbytes <= binsize(nunits))
| Inf | ||||||||||||||||||||||||
| 775 | break; executed 2147483647 times by 1 test: break;Executed by:
| Inf | ||||||||||||||||||||||||
| 776 | - | |||||||||||||||||||||||||
| 777 | /* Silently reject too-large requests. */ | - | ||||||||||||||||||||||||
| 778 | if (nunits >= NBUCKETS)
| 0-Inf | ||||||||||||||||||||||||
| 779 | return ((PTR_T) NULL); never executed: return ((void *) ((void *)0) ); | 0 | ||||||||||||||||||||||||
| 780 | - | |||||||||||||||||||||||||
| 781 | /* In case this is reentrant use of malloc from signal handler, | - | ||||||||||||||||||||||||
| 782 | pick a block size that no other malloc level is currently | - | ||||||||||||||||||||||||
| 783 | trying to allocate. That's the easiest harmless way not to | - | ||||||||||||||||||||||||
| 784 | interfere with the other level of execution. */ | - | ||||||||||||||||||||||||
| 785 | #ifdef MALLOC_STATS | - | ||||||||||||||||||||||||
| 786 | if (busy[nunits]) _mstats.nrecurse++; never executed: _mstats.nrecurse++;
| 0-Inf | ||||||||||||||||||||||||
| 787 | #endif | - | ||||||||||||||||||||||||
| 788 | while (busy[nunits]) nunits++; never executed: nunits++;
| 0-Inf | ||||||||||||||||||||||||
| 789 | busy[nunits] = 1; | - | ||||||||||||||||||||||||
| 790 | - | |||||||||||||||||||||||||
| 791 | if (nunits > maxbuck)
| 27177-Inf | ||||||||||||||||||||||||
| 792 | maxbuck = nunits; executed 27177 times by 1 test: maxbuck = nunits;Executed by:
| 27177 | ||||||||||||||||||||||||
| 793 | - | |||||||||||||||||||||||||
| 794 | /* If there are no blocks of the appropriate size, go get some */ | - | ||||||||||||||||||||||||
| 795 | if (nextf[nunits] == 0)
| 3186477-Inf | ||||||||||||||||||||||||
| 796 | morecore (nunits); executed 3186477 times by 1 test: morecore (nunits);Executed by:
| 3186477 | ||||||||||||||||||||||||
| 797 | - | |||||||||||||||||||||||||
| 798 | /* Get one block off the list, and set the new list head */ | - | ||||||||||||||||||||||||
| 799 | if ((p = nextf[nunits]) == NULL)
| 0-Inf | ||||||||||||||||||||||||
| 800 | { | - | ||||||||||||||||||||||||
| 801 | busy[nunits] = 0; | - | ||||||||||||||||||||||||
| 802 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||
| 803 | } | - | ||||||||||||||||||||||||
| 804 | nextf[nunits] = CHAIN (p); | - | ||||||||||||||||||||||||
| 805 | busy[nunits] = 0; | - | ||||||||||||||||||||||||
| 806 | - | |||||||||||||||||||||||||
| 807 | /* Check for free block clobbered */ | - | ||||||||||||||||||||||||
| 808 | /* If not for this check, we would gobble a clobbered free chain ptr | - | ||||||||||||||||||||||||
| 809 | and bomb out on the NEXT allocate of this size block */ | - | ||||||||||||||||||||||||
| 810 | if (p->mh_alloc != ISFREE || p->mh_index != nunits)
| 0-Inf | ||||||||||||||||||||||||
| 811 | xbotch ((PTR_T)(p+1), 0, _("malloc: block on free list clobbered"), file, line); never executed: xbotch ((void *)(p+1), 0, dcgettext (((void *)0), "malloc: block on free list clobbered" , 5) , file, line); | 0 | ||||||||||||||||||||||||
| 812 | - | |||||||||||||||||||||||||
| 813 | /* Fill in the info, and set up the magic numbers for range checking. */ | - | ||||||||||||||||||||||||
| 814 | p->mh_alloc = ISALLOC; | - | ||||||||||||||||||||||||
| 815 | p->mh_magic2 = MAGIC2; | - | ||||||||||||||||||||||||
| 816 | p->mh_nbytes = n; | - | ||||||||||||||||||||||||
| 817 | - | |||||||||||||||||||||||||
| 818 | /* End guard */ | - | ||||||||||||||||||||||||
| 819 | mg.i = n; | - | ||||||||||||||||||||||||
| 820 | z = mg.s; | - | ||||||||||||||||||||||||
| 821 | m = (char *) (p + 1) + n; | - | ||||||||||||||||||||||||
| 822 | *m++ = *z++, *m++ = *z++, *m++ = *z++, *m++ = *z++; | - | ||||||||||||||||||||||||
| 823 | - | |||||||||||||||||||||||||
| 824 | #ifdef MEMSCRAMBLE | - | ||||||||||||||||||||||||
| 825 | if (n)
| 80-Inf | ||||||||||||||||||||||||
| 826 | MALLOC_MEMSET ((char *)(p + 1), 0xdf, n); /* scramble previous contents */ executed 1162447761 times by 1 test: mcn = 0;Executed by:
executed 1176959061 times by 1 test: end of blockExecuted by:
executed 2147483647 times by 1 test: break;Executed by:
executed 2147483647 times by 1 test: end of blockExecuted by:
executed 2147483647 times by 1 test: end of blockExecuted by:
executed 2147483647 times by 1 test: end of blockExecuted by:
executed 399801898 times by 1 test: memset (((char *)(p + 1)), (0xdf), (n));Executed by:
executed 2147483647 times by 1 test: end of blockExecuted by:
code before this statement executed 2147483647 times by 1 test: case 7:Executed by:
code before this statement executed 2147483647 times by 1 test: case 6:Executed by:
code before this statement executed 2147483647 times by 1 test: case 5:Executed by:
code before this statement executed 2147483647 times by 1 test: case 4:Executed by:
code before this statement executed 2147483647 times by 1 test: case 3:Executed by:
code before this statement executed 2147483647 times by 1 test: case 2:Executed by:
code before this statement executed 2147483647 times by 1 test: case 1:Executed by:
executed 784811589 times by 1 test: case 0:Executed by:
executed 72406154 times by 1 test: case 7:Executed by:
executed 103837580 times by 1 test: case 6:Executed by:
executed 173970909 times by 1 test: case 5:Executed by:
executed 121802483 times by 1 test: case 4:Executed by:
executed 313187203 times by 1 test: case 3:Executed by:
executed 601789411 times by 1 test: case 2:Executed by:
executed 167601493 times by 1 test: case 1:Executed by:
| 72406154-Inf | ||||||||||||||||||||||||
| 827 | #endif | - | ||||||||||||||||||||||||
| 828 | #ifdef MALLOC_STATS | - | ||||||||||||||||||||||||
| 829 | _mstats.nmalloc[nunits]++; | - | ||||||||||||||||||||||||
| 830 | _mstats.tmalloc[nunits]++; | - | ||||||||||||||||||||||||
| 831 | _mstats.nmal++; | - | ||||||||||||||||||||||||
| 832 | _mstats.bytesreq += n; | - | ||||||||||||||||||||||||
| 833 | #endif /* MALLOC_STATS */ | - | ||||||||||||||||||||||||
| 834 | - | |||||||||||||||||||||||||
| 835 | #ifdef MALLOC_TRACE | - | ||||||||||||||||||||||||
| 836 | if (malloc_trace && (flags & MALLOC_NOTRACE) == 0)
| 0-Inf | ||||||||||||||||||||||||
| 837 | mtrace_alloc ("malloc", p + 1, n, file, line); never executed: mtrace_alloc ("malloc", p + 1, n, file, line); | 0 | ||||||||||||||||||||||||
| 838 | else if (_malloc_trace_buckets[nunits])
| 0-Inf | ||||||||||||||||||||||||
| 839 | mtrace_alloc ("malloc", p + 1, n, file, line); never executed: mtrace_alloc ("malloc", p + 1, n, file, line); | 0 | ||||||||||||||||||||||||
| 840 | #endif | - | ||||||||||||||||||||||||
| 841 | - | |||||||||||||||||||||||||
| 842 | #ifdef MALLOC_REGISTER | - | ||||||||||||||||||||||||
| 843 | if (malloc_register && (flags & MALLOC_NOREG) == 0)
| 35046-Inf | ||||||||||||||||||||||||
| 844 | mregister_alloc ("malloc", p + 1, n, file, line); executed 2147483647 times by 1 test: mregister_alloc ("malloc", p + 1, n, file, line);Executed by:
| Inf | ||||||||||||||||||||||||
| 845 | #endif | - | ||||||||||||||||||||||||
| 846 | - | |||||||||||||||||||||||||
| 847 | #ifdef MALLOC_WATCH | - | ||||||||||||||||||||||||
| 848 | if (_malloc_nwatch > 0)
| 0-Inf | ||||||||||||||||||||||||
| 849 | _malloc_ckwatch (p + 1, file, line, W_ALLOC, n); never executed: _malloc_ckwatch (p + 1, file, line, 0x01, n); | 0 | ||||||||||||||||||||||||
| 850 | #endif | - | ||||||||||||||||||||||||
| 851 | - | |||||||||||||||||||||||||
| 852 | return (PTR_T) (p + 1); executed 2147483647 times by 1 test: return (void *) (p + 1);Executed by:
| Inf | ||||||||||||||||||||||||
| 853 | } | - | ||||||||||||||||||||||||
| 854 | - | |||||||||||||||||||||||||
| 855 | static void | - | ||||||||||||||||||||||||
| 856 | internal_free (mem, file, line, flags) | - | ||||||||||||||||||||||||
| 857 | PTR_T mem; | - | ||||||||||||||||||||||||
| 858 | const char *file; | - | ||||||||||||||||||||||||
| 859 | int line, flags; | - | ||||||||||||||||||||||||
| 860 | { | - | ||||||||||||||||||||||||
| 861 | register union mhead *p; | - | ||||||||||||||||||||||||
| 862 | register char *ap, *z; | - | ||||||||||||||||||||||||
| 863 | register int nunits; | - | ||||||||||||||||||||||||
| 864 | register unsigned int nbytes; | - | ||||||||||||||||||||||||
| 865 | int ubytes; /* caller-requested size */ | - | ||||||||||||||||||||||||
| 866 | mguard_t mg; | - | ||||||||||||||||||||||||
| 867 | - | |||||||||||||||||||||||||
| 868 | if ((ap = (char *)mem) == 0)
| 66190-Inf | ||||||||||||||||||||||||
| 869 | return; executed 66190 times by 1 test: return;Executed by:
| 66190 | ||||||||||||||||||||||||
| 870 | - | |||||||||||||||||||||||||
| 871 | p = (union mhead *) ap - 1; | - | ||||||||||||||||||||||||
| 872 | - | |||||||||||||||||||||||||
| 873 | if (p->mh_alloc == ISMEMALIGN)
| 0-Inf | ||||||||||||||||||||||||
| 874 | { | - | ||||||||||||||||||||||||
| 875 | ap -= p->mh_nbytes; | - | ||||||||||||||||||||||||
| 876 | p = (union mhead *) ap - 1; | - | ||||||||||||||||||||||||
| 877 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 878 | - | |||||||||||||||||||||||||
| 879 | #if defined (MALLOC_TRACE) || defined (MALLOC_REGISTER) || defined (MALLOC_WATCH) | - | ||||||||||||||||||||||||
| 880 | if (malloc_trace || malloc_register || _malloc_nwatch > 0)
| 0-Inf | ||||||||||||||||||||||||
| 881 | ubytes = p->mh_nbytes; executed 2147483647 times by 1 test: ubytes = p->minfo.mi_nbytes;Executed by:
| Inf | ||||||||||||||||||||||||
| 882 | #endif | - | ||||||||||||||||||||||||
| 883 | - | |||||||||||||||||||||||||
| 884 | if (p->mh_alloc != ISALLOC)
| 0-Inf | ||||||||||||||||||||||||
| 885 | { | - | ||||||||||||||||||||||||
| 886 | if (p->mh_alloc == ISFREE)
| 0 | ||||||||||||||||||||||||
| 887 | xbotch (mem, ERR_DUPFREE, never executed: xbotch (mem, 0x01, dcgettext (((void *)0), "free: called with already freed block argument" , 5) , file, line); | 0 | ||||||||||||||||||||||||
| 888 | _("free: called with already freed block argument"), file, line); never executed: xbotch (mem, 0x01, dcgettext (((void *)0), "free: called with already freed block argument" , 5) , file, line); | 0 | ||||||||||||||||||||||||
| 889 | else | - | ||||||||||||||||||||||||
| 890 | xbotch (mem, ERR_UNALLOC, never executed: xbotch (mem, 0x02, dcgettext (((void *)0), "free: called with unallocated block argument" , 5) , file, line); | 0 | ||||||||||||||||||||||||
| 891 | _("free: called with unallocated block argument"), file, line); never executed: xbotch (mem, 0x02, dcgettext (((void *)0), "free: called with unallocated block argument" , 5) , file, line); | 0 | ||||||||||||||||||||||||
| 892 | } | - | ||||||||||||||||||||||||
| 893 | - | |||||||||||||||||||||||||
| 894 | ASSERT (p->mh_magic2 == MAGIC2); never executed: xbotch((void *)0, 0x08, "p->minfo.mi_magic2 == 0x5555", file, line);
| 0-Inf | ||||||||||||||||||||||||
| 895 | - | |||||||||||||||||||||||||
| 896 | nunits = p->mh_index; | - | ||||||||||||||||||||||||
| 897 | nbytes = ALLOCATED_BYTES(p->mh_nbytes); | - | ||||||||||||||||||||||||
| 898 | /* Since the sizeof(u_bits32_t) bytes before the memory handed to the user | - | ||||||||||||||||||||||||
| 899 | are now used for the number of bytes allocated, a simple check of | - | ||||||||||||||||||||||||
| 900 | mh_magic2 is no longer sufficient to catch things like p[-1] = 'x'. | - | ||||||||||||||||||||||||
| 901 | We sanity-check the value of mh_nbytes against the size of the blocks | - | ||||||||||||||||||||||||
| 902 | in the appropriate bucket before we use it. This can still cause problems | - | ||||||||||||||||||||||||
| 903 | and obscure errors if mh_nbytes is wrong but still within range; the | - | ||||||||||||||||||||||||
| 904 | checks against the size recorded at the end of the chunk will probably | - | ||||||||||||||||||||||||
| 905 | fail then. Using MALLOC_REGISTER will help here, since it saves the | - | ||||||||||||||||||||||||
| 906 | original number of bytes requested. */ | - | ||||||||||||||||||||||||
| 907 | - | |||||||||||||||||||||||||
| 908 | if (IN_BUCKET(nbytes, nunits) == 0)
| 0-Inf | ||||||||||||||||||||||||
| 909 | xbotch (mem, ERR_UNDERFLOW, never executed: xbotch (mem, 0x04, dcgettext (((void *)0), "free: underflow detected; mh_nbytes out of range" , 5) , file, line); | 0 | ||||||||||||||||||||||||
| 910 | _("free: underflow detected; mh_nbytes out of range"), file, line); never executed: xbotch (mem, 0x04, dcgettext (((void *)0), "free: underflow detected; mh_nbytes out of range" , 5) , file, line); | 0 | ||||||||||||||||||||||||
| 911 | - | |||||||||||||||||||||||||
| 912 | ap += p->mh_nbytes; | - | ||||||||||||||||||||||||
| 913 | z = mg.s; | - | ||||||||||||||||||||||||
| 914 | *z++ = *ap++, *z++ = *ap++, *z++ = *ap++, *z++ = *ap++; | - | ||||||||||||||||||||||||
| 915 | if (mg.i != p->mh_nbytes)
| 0-Inf | ||||||||||||||||||||||||
| 916 | xbotch (mem, ERR_ASSERT_FAILED, _("free: start and end chunk sizes differ"), file, line); never executed: xbotch (mem, 0x08, dcgettext (((void *)0), "free: start and end chunk sizes differ" , 5) , file, line); | 0 | ||||||||||||||||||||||||
| 917 | - | |||||||||||||||||||||||||
| 918 | #if GLIBC21 | - | ||||||||||||||||||||||||
| 919 | if (nunits >= LESSCORE_MIN && ((char *)p + binsize(nunits) == sbrk (0))) | - | ||||||||||||||||||||||||
| 920 | #else | - | ||||||||||||||||||||||||
| 921 | if (nunits >= LESSCORE_MIN && ((char *)p + binsize(nunits) == memtop))
| 521916-Inf | ||||||||||||||||||||||||
| 922 | #endif | - | ||||||||||||||||||||||||
| 923 | { | - | ||||||||||||||||||||||||
| 924 | /* If above LESSCORE_FRC, give back unconditionally. This should be set | - | ||||||||||||||||||||||||
| 925 | high enough to be infrequently encountered. If between LESSCORE_MIN | - | ||||||||||||||||||||||||
| 926 | and LESSCORE_FRC, call lesscore if the bucket is marked as busy or if | - | ||||||||||||||||||||||||
| 927 | there's already a block on the free list. */ | - | ||||||||||||||||||||||||
| 928 | if ((nunits >= LESSCORE_FRC) || busy[nunits] || nextf[nunits] != 0)
| 0-57334886 | ||||||||||||||||||||||||
| 929 | { | - | ||||||||||||||||||||||||
| 930 | lesscore (nunits); | - | ||||||||||||||||||||||||
| 931 | /* keeps the tracing and registering code in one place */ | - | ||||||||||||||||||||||||
| 932 | goto free_return; executed 1722 times by 1 test: goto free_return;Executed by:
| 1722 | ||||||||||||||||||||||||
| 933 | } | - | ||||||||||||||||||||||||
| 934 | } executed 57334862 times by 1 test: end of blockExecuted by:
| 57334862 | ||||||||||||||||||||||||
| 935 | - | |||||||||||||||||||||||||
| 936 | #ifdef MEMSCRAMBLE | - | ||||||||||||||||||||||||
| 937 | if (p->mh_nbytes)
| 80-Inf | ||||||||||||||||||||||||
| 938 | MALLOC_MEMSET (mem, 0xcf, p->mh_nbytes); executed 1160792681 times by 1 test: mcn = 0;Executed by:
executed 1169118356 times by 1 test: end of blockExecuted by:
executed 2147483647 times by 1 test: break;Executed by:
executed 2147483647 times by 1 test: end of blockExecuted by:
executed 2147483647 times by 1 test: end of blockExecuted by:
executed 2147483647 times by 1 test: end of blockExecuted by:
executed 398923759 times by 1 test: memset ((mem), (0xcf), (p->minfo.mi_nbytes));Executed by:
executed 2147483647 times by 1 test: end of blockExecuted by:
code before this statement executed 2147483647 times by 1 test: case 7:Executed by:
code before this statement executed 2147483647 times by 1 test: case 6:Executed by:
code before this statement executed 2147483647 times by 1 test: case 5:Executed by:
code before this statement executed 2147483647 times by 1 test: case 4:Executed by:
code before this statement executed 2147483647 times by 1 test: case 3:Executed by:
code before this statement executed 2147483647 times by 1 test: case 2:Executed by:
code before this statement executed 2147483647 times by 1 test: case 1:Executed by:
executed 778061153 times by 1 test: case 0:Executed by:
executed 72168244 times by 1 test: case 7:Executed by:
executed 103651051 times by 1 test: case 6:Executed by:
executed 173376289 times by 1 test: case 5:Executed by:
executed 121350200 times by 1 test: case 4:Executed by:
executed 312755919 times by 1 test: case 3:Executed by:
executed 601138706 times by 1 test: case 2:Executed by:
executed 167409475 times by 1 test: case 1:Executed by:
| 72168244-Inf | ||||||||||||||||||||||||
| 939 | #endif | - | ||||||||||||||||||||||||
| 940 | - | |||||||||||||||||||||||||
| 941 | ASSERT (nunits < NBUCKETS); never executed: xbotch((void *)0, 0x08, "nunits < 30", file, line);
| 0-Inf | ||||||||||||||||||||||||
| 942 | - | |||||||||||||||||||||||||
| 943 | if (busy[nunits] == 1)
| 0-Inf | ||||||||||||||||||||||||
| 944 | { | - | ||||||||||||||||||||||||
| 945 | xsplit (p, nunits); /* split block and add to different chain */ | - | ||||||||||||||||||||||||
| 946 | goto free_return; never executed: goto free_return; | 0 | ||||||||||||||||||||||||
| 947 | } | - | ||||||||||||||||||||||||
| 948 | - | |||||||||||||||||||||||||
| 949 | p->mh_alloc = ISFREE; | - | ||||||||||||||||||||||||
| 950 | /* Protect against signal handlers calling malloc. */ | - | ||||||||||||||||||||||||
| 951 | busy[nunits] = 1; | - | ||||||||||||||||||||||||
| 952 | /* Put this block on the free list. */ | - | ||||||||||||||||||||||||
| 953 | CHAIN (p) = nextf[nunits]; | - | ||||||||||||||||||||||||
| 954 | nextf[nunits] = p; | - | ||||||||||||||||||||||||
| 955 | busy[nunits] = 0; | - | ||||||||||||||||||||||||
| 956 | - | |||||||||||||||||||||||||
| 957 | free_return: code before this statement executed 2147483647 times by 1 test: free_return:Executed by:
| Inf | ||||||||||||||||||||||||
| 958 | ; /* Empty statement in case this is the end of the function */ | - | ||||||||||||||||||||||||
| 959 | - | |||||||||||||||||||||||||
| 960 | #ifdef MALLOC_STATS | - | ||||||||||||||||||||||||
| 961 | _mstats.nmalloc[nunits]--; | - | ||||||||||||||||||||||||
| 962 | _mstats.nfre++; | - | ||||||||||||||||||||||||
| 963 | #endif /* MALLOC_STATS */ | - | ||||||||||||||||||||||||
| 964 | - | |||||||||||||||||||||||||
| 965 | #ifdef MALLOC_TRACE | - | ||||||||||||||||||||||||
| 966 | if (malloc_trace && (flags & MALLOC_NOTRACE) == 0)
| 0-Inf | ||||||||||||||||||||||||
| 967 | mtrace_free (mem, ubytes, file, line); never executed: mtrace_free (mem, ubytes, file, line); | 0 | ||||||||||||||||||||||||
| 968 | else if (_malloc_trace_buckets[nunits])
| 0-Inf | ||||||||||||||||||||||||
| 969 | mtrace_free (mem, ubytes, file, line); never executed: mtrace_free (mem, ubytes, file, line); | 0 | ||||||||||||||||||||||||
| 970 | #endif | - | ||||||||||||||||||||||||
| 971 | - | |||||||||||||||||||||||||
| 972 | #ifdef MALLOC_REGISTER | - | ||||||||||||||||||||||||
| 973 | if (malloc_register && (flags & MALLOC_NOREG) == 0)
| 0-Inf | ||||||||||||||||||||||||
| 974 | mregister_free (mem, ubytes, file, line); executed 2147483647 times by 1 test: mregister_free (mem, ubytes, file, line);Executed by:
| Inf | ||||||||||||||||||||||||
| 975 | #endif | - | ||||||||||||||||||||||||
| 976 | - | |||||||||||||||||||||||||
| 977 | #ifdef MALLOC_WATCH | - | ||||||||||||||||||||||||
| 978 | if (_malloc_nwatch > 0)
| 0-Inf | ||||||||||||||||||||||||
| 979 | _malloc_ckwatch (mem, file, line, W_FREE, ubytes); never executed: _malloc_ckwatch (mem, file, line, 0x02, ubytes); | 0 | ||||||||||||||||||||||||
| 980 | #endif | - | ||||||||||||||||||||||||
| 981 | } executed 2147483647 times by 1 test: end of blockExecuted by:
| Inf | ||||||||||||||||||||||||
| 982 | - | |||||||||||||||||||||||||
| 983 | static PTR_T | - | ||||||||||||||||||||||||
| 984 | internal_realloc (mem, n, file, line, flags) | - | ||||||||||||||||||||||||
| 985 | PTR_T mem; | - | ||||||||||||||||||||||||
| 986 | register size_t n; | - | ||||||||||||||||||||||||
| 987 | const char *file; | - | ||||||||||||||||||||||||
| 988 | int line, flags; | - | ||||||||||||||||||||||||
| 989 | { | - | ||||||||||||||||||||||||
| 990 | register union mhead *p; | - | ||||||||||||||||||||||||
| 991 | register u_bits32_t tocopy; | - | ||||||||||||||||||||||||
| 992 | register unsigned int nbytes; | - | ||||||||||||||||||||||||
| 993 | register int nunits; | - | ||||||||||||||||||||||||
| 994 | register char *m, *z; | - | ||||||||||||||||||||||||
| 995 | mguard_t mg; | - | ||||||||||||||||||||||||
| 996 | - | |||||||||||||||||||||||||
| 997 | #ifdef MALLOC_STATS | - | ||||||||||||||||||||||||
| 998 | _mstats.nrealloc++; | - | ||||||||||||||||||||||||
| 999 | #endif | - | ||||||||||||||||||||||||
| 1000 | - | |||||||||||||||||||||||||
| 1001 | if (n == 0)
| 0-4729931 | ||||||||||||||||||||||||
| 1002 | { | - | ||||||||||||||||||||||||
| 1003 | internal_free (mem, file, line, MALLOC_INTERNAL); | - | ||||||||||||||||||||||||
| 1004 | return (NULL); never executed: return ( ((void *)0) ); | 0 | ||||||||||||||||||||||||
| 1005 | } | - | ||||||||||||||||||||||||
| 1006 | if ((p = (union mhead *) mem) == 0)
| 94032-4635899 | ||||||||||||||||||||||||
| 1007 | return internal_malloc (n, file, line, MALLOC_INTERNAL); executed 4635899 times by 1 test: return internal_malloc (n, file, line, 0x02);Executed by:
| 4635899 | ||||||||||||||||||||||||
| 1008 | - | |||||||||||||||||||||||||
| 1009 | p--; | - | ||||||||||||||||||||||||
| 1010 | nunits = p->mh_index; | - | ||||||||||||||||||||||||
| 1011 | ASSERT (nunits < NBUCKETS); never executed: xbotch((void *)0, 0x08, "nunits < 30", file, line);
| 0-94032 | ||||||||||||||||||||||||
| 1012 | - | |||||||||||||||||||||||||
| 1013 | if (p->mh_alloc != ISALLOC)
| 0-94032 | ||||||||||||||||||||||||
| 1014 | xbotch (mem, ERR_UNALLOC, never executed: xbotch (mem, 0x02, dcgettext (((void *)0), "realloc: called with unallocated block argument" , 5) , file, line); | 0 | ||||||||||||||||||||||||
| 1015 | _("realloc: called with unallocated block argument"), file, line); never executed: xbotch (mem, 0x02, dcgettext (((void *)0), "realloc: called with unallocated block argument" , 5) , file, line); | 0 | ||||||||||||||||||||||||
| 1016 | - | |||||||||||||||||||||||||
| 1017 | ASSERT (p->mh_magic2 == MAGIC2); never executed: xbotch((void *)0, 0x08, "p->minfo.mi_magic2 == 0x5555", file, line);
| 0-94032 | ||||||||||||||||||||||||
| 1018 | nbytes = ALLOCATED_BYTES(p->mh_nbytes); | - | ||||||||||||||||||||||||
| 1019 | /* Since the sizeof(u_bits32_t) bytes before the memory handed to the user | - | ||||||||||||||||||||||||
| 1020 | are now used for the number of bytes allocated, a simple check of | - | ||||||||||||||||||||||||
| 1021 | mh_magic2 is no longer sufficient to catch things like p[-1] = 'x'. | - | ||||||||||||||||||||||||
| 1022 | We sanity-check the value of mh_nbytes against the size of the blocks | - | ||||||||||||||||||||||||
| 1023 | in the appropriate bucket before we use it. This can still cause problems | - | ||||||||||||||||||||||||
| 1024 | and obscure errors if mh_nbytes is wrong but still within range; the | - | ||||||||||||||||||||||||
| 1025 | checks against the size recorded at the end of the chunk will probably | - | ||||||||||||||||||||||||
| 1026 | fail then. Using MALLOC_REGISTER will help here, since it saves the | - | ||||||||||||||||||||||||
| 1027 | original number of bytes requested. */ | - | ||||||||||||||||||||||||
| 1028 | if (IN_BUCKET(nbytes, nunits) == 0)
| 0-94032 | ||||||||||||||||||||||||
| 1029 | xbotch (mem, ERR_UNDERFLOW, never executed: xbotch (mem, 0x04, dcgettext (((void *)0), "realloc: underflow detected; mh_nbytes out of range" , 5) , file, line); | 0 | ||||||||||||||||||||||||
| 1030 | _("realloc: underflow detected; mh_nbytes out of range"), file, line); never executed: xbotch (mem, 0x04, dcgettext (((void *)0), "realloc: underflow detected; mh_nbytes out of range" , 5) , file, line); | 0 | ||||||||||||||||||||||||
| 1031 | - | |||||||||||||||||||||||||
| 1032 | m = (char *)mem + (tocopy = p->mh_nbytes); | - | ||||||||||||||||||||||||
| 1033 | z = mg.s; | - | ||||||||||||||||||||||||
| 1034 | *z++ = *m++, *z++ = *m++, *z++ = *m++, *z++ = *m++; | - | ||||||||||||||||||||||||
| 1035 | if (mg.i != p->mh_nbytes)
| 0-94032 | ||||||||||||||||||||||||
| 1036 | xbotch (mem, ERR_ASSERT_FAILED, _("realloc: start and end chunk sizes differ"), file, line); never executed: xbotch (mem, 0x08, dcgettext (((void *)0), "realloc: start and end chunk sizes differ" , 5) , file, line); | 0 | ||||||||||||||||||||||||
| 1037 | - | |||||||||||||||||||||||||
| 1038 | #ifdef MALLOC_WATCH | - | ||||||||||||||||||||||||
| 1039 | if (_malloc_nwatch > 0)
| 0-94032 | ||||||||||||||||||||||||
| 1040 | _malloc_ckwatch (p + 1, file, line, W_REALLOC, n); never executed: _malloc_ckwatch (p + 1, file, line, 0x04, n); | 0 | ||||||||||||||||||||||||
| 1041 | #endif | - | ||||||||||||||||||||||||
| 1042 | #ifdef MALLOC_STATS | - | ||||||||||||||||||||||||
| 1043 | _mstats.bytesreq += (n < tocopy) ? 0 : n - tocopy;
| 101-93931 | ||||||||||||||||||||||||
| 1044 | #endif | - | ||||||||||||||||||||||||
| 1045 | - | |||||||||||||||||||||||||
| 1046 | /* If we're reallocating to the same size as previously, return now */ | - | ||||||||||||||||||||||||
| 1047 | if (n == p->mh_nbytes)
| 167-93865 | ||||||||||||||||||||||||
| 1048 | return mem; executed 167 times by 1 test: return mem;Executed by:
| 167 | ||||||||||||||||||||||||
| 1049 | - | |||||||||||||||||||||||||
| 1050 | /* See if desired size rounds to same power of 2 as actual size. */ | - | ||||||||||||||||||||||||
| 1051 | nbytes = ALLOCATED_BYTES(n); | - | ||||||||||||||||||||||||
| 1052 | - | |||||||||||||||||||||||||
| 1053 | /* If ok, use the same block, just marking its size as changed. */ | - | ||||||||||||||||||||||||
| 1054 | if (RIGHT_BUCKET(nbytes, nunits) || RIGHT_BUCKET(nbytes, nunits-1))
| 4-93765 | ||||||||||||||||||||||||
| 1055 | { | - | ||||||||||||||||||||||||
| 1056 | #if 0 | - | ||||||||||||||||||||||||
| 1057 | m = (char *)mem + p->mh_nbytes; | - | ||||||||||||||||||||||||
| 1058 | #else | - | ||||||||||||||||||||||||
| 1059 | /* Compensate for increment above. */ | - | ||||||||||||||||||||||||
| 1060 | m -= 4; | - | ||||||||||||||||||||||||
| 1061 | #endif | - | ||||||||||||||||||||||||
| 1062 | *m++ = 0; *m++ = 0; *m++ = 0; *m++ = 0; | - | ||||||||||||||||||||||||
| 1063 | m = (char *)mem + (p->mh_nbytes = n); | - | ||||||||||||||||||||||||
| 1064 | - | |||||||||||||||||||||||||
| 1065 | mg.i = n; | - | ||||||||||||||||||||||||
| 1066 | z = mg.s; | - | ||||||||||||||||||||||||
| 1067 | *m++ = *z++, *m++ = *z++, *m++ = *z++, *m++ = *z++; | - | ||||||||||||||||||||||||
| 1068 | - | |||||||||||||||||||||||||
| 1069 | return mem; executed 58819 times by 1 test: return mem;Executed by:
| 58819 | ||||||||||||||||||||||||
| 1070 | } | - | ||||||||||||||||||||||||
| 1071 | - | |||||||||||||||||||||||||
| 1072 | if (n < tocopy)
| 96-34950 | ||||||||||||||||||||||||
| 1073 | tocopy = n; executed 96 times by 1 test: tocopy = n;Executed by:
| 96 | ||||||||||||||||||||||||
| 1074 | - | |||||||||||||||||||||||||
| 1075 | #ifdef MALLOC_STATS | - | ||||||||||||||||||||||||
| 1076 | _mstats.nrcopy++; | - | ||||||||||||||||||||||||
| 1077 | #endif | - | ||||||||||||||||||||||||
| 1078 | - | |||||||||||||||||||||||||
| 1079 | if ((m = internal_malloc (n, file, line, MALLOC_INTERNAL|MALLOC_NOTRACE|MALLOC_NOREG)) == 0)
| 0-35046 | ||||||||||||||||||||||||
| 1080 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 1081 | FASTCOPY (mem, m, tocopy); | - | ||||||||||||||||||||||||
| 1082 | internal_free (mem, file, line, MALLOC_INTERNAL); | - | ||||||||||||||||||||||||
| 1083 | - | |||||||||||||||||||||||||
| 1084 | #ifdef MALLOC_TRACE | - | ||||||||||||||||||||||||
| 1085 | if (malloc_trace && (flags & MALLOC_NOTRACE) == 0)
| 0-35046 | ||||||||||||||||||||||||
| 1086 | mtrace_alloc ("realloc", m, n, file, line); never executed: mtrace_alloc ("realloc", m, n, file, line); | 0 | ||||||||||||||||||||||||
| 1087 | else if (_malloc_trace_buckets[nunits])
| 0-35046 | ||||||||||||||||||||||||
| 1088 | mtrace_alloc ("realloc", m, n, file, line); never executed: mtrace_alloc ("realloc", m, n, file, line); | 0 | ||||||||||||||||||||||||
| 1089 | #endif | - | ||||||||||||||||||||||||
| 1090 | - | |||||||||||||||||||||||||
| 1091 | #ifdef MALLOC_REGISTER | - | ||||||||||||||||||||||||
| 1092 | if (malloc_register && (flags & MALLOC_NOREG) == 0)
| 0-35046 | ||||||||||||||||||||||||
| 1093 | mregister_alloc ("realloc", m, n, file, line); executed 35046 times by 1 test: mregister_alloc ("realloc", m, n, file, line);Executed by:
| 35046 | ||||||||||||||||||||||||
| 1094 | #endif | - | ||||||||||||||||||||||||
| 1095 | - | |||||||||||||||||||||||||
| 1096 | #ifdef MALLOC_WATCH | - | ||||||||||||||||||||||||
| 1097 | if (_malloc_nwatch > 0)
| 0-35046 | ||||||||||||||||||||||||
| 1098 | _malloc_ckwatch (m, file, line, W_RESIZED, n); never executed: _malloc_ckwatch (m, file, line, 0x08, n); | 0 | ||||||||||||||||||||||||
| 1099 | #endif | - | ||||||||||||||||||||||||
| 1100 | - | |||||||||||||||||||||||||
| 1101 | return m; executed 35046 times by 1 test: return m;Executed by:
| 35046 | ||||||||||||||||||||||||
| 1102 | } | - | ||||||||||||||||||||||||
| 1103 | - | |||||||||||||||||||||||||
| 1104 | static PTR_T | - | ||||||||||||||||||||||||
| 1105 | internal_memalign (alignment, size, file, line, flags) | - | ||||||||||||||||||||||||
| 1106 | size_t alignment; | - | ||||||||||||||||||||||||
| 1107 | size_t size; | - | ||||||||||||||||||||||||
| 1108 | const char *file; | - | ||||||||||||||||||||||||
| 1109 | int line, flags; | - | ||||||||||||||||||||||||
| 1110 | { | - | ||||||||||||||||||||||||
| 1111 | register char *ptr; | - | ||||||||||||||||||||||||
| 1112 | register char *aligned; | - | ||||||||||||||||||||||||
| 1113 | register union mhead *p; | - | ||||||||||||||||||||||||
| 1114 | - | |||||||||||||||||||||||||
| 1115 | ptr = internal_malloc (size + alignment, file, line, MALLOC_INTERNAL); | - | ||||||||||||||||||||||||
| 1116 | - | |||||||||||||||||||||||||
| 1117 | if (ptr == 0)
| 0 | ||||||||||||||||||||||||
| 1118 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 1119 | /* If entire block has the desired alignment, just accept it. */ | - | ||||||||||||||||||||||||
| 1120 | if (((long) ptr & (alignment - 1)) == 0)
| 0 | ||||||||||||||||||||||||
| 1121 | return ptr; never executed: return ptr; | 0 | ||||||||||||||||||||||||
| 1122 | /* Otherwise, get address of byte in the block that has that alignment. */ | - | ||||||||||||||||||||||||
| 1123 | #if 0 | - | ||||||||||||||||||||||||
| 1124 | aligned = (char *) (((long) ptr + alignment - 1) & -alignment); | - | ||||||||||||||||||||||||
| 1125 | #else | - | ||||||||||||||||||||||||
| 1126 | aligned = (char *) (((long) ptr + alignment - 1) & (~alignment + 1)); | - | ||||||||||||||||||||||||
| 1127 | #endif | - | ||||||||||||||||||||||||
| 1128 | - | |||||||||||||||||||||||||
| 1129 | /* Store a suitable indication of how to free the block, | - | ||||||||||||||||||||||||
| 1130 | so that free can find the true beginning of it. */ | - | ||||||||||||||||||||||||
| 1131 | p = (union mhead *) aligned - 1; | - | ||||||||||||||||||||||||
| 1132 | p->mh_nbytes = aligned - ptr; | - | ||||||||||||||||||||||||
| 1133 | p->mh_alloc = ISMEMALIGN; | - | ||||||||||||||||||||||||
| 1134 | - | |||||||||||||||||||||||||
| 1135 | return aligned; never executed: return aligned; | 0 | ||||||||||||||||||||||||
| 1136 | } | - | ||||||||||||||||||||||||
| 1137 | - | |||||||||||||||||||||||||
| 1138 | int | - | ||||||||||||||||||||||||
| 1139 | posix_memalign (memptr, alignment, size) | - | ||||||||||||||||||||||||
| 1140 | void **memptr; | - | ||||||||||||||||||||||||
| 1141 | size_t alignment, size; | - | ||||||||||||||||||||||||
| 1142 | { | - | ||||||||||||||||||||||||
| 1143 | void *mem; | - | ||||||||||||||||||||||||
| 1144 | - | |||||||||||||||||||||||||
| 1145 | /* Perform posix-mandated error checking here */ | - | ||||||||||||||||||||||||
| 1146 | if ((alignment % sizeof (void *) != 0) || alignment == 0)
| 0 | ||||||||||||||||||||||||
| 1147 | return EINVAL; never executed: return 22 ; | 0 | ||||||||||||||||||||||||
| 1148 | else if (powerof2 (alignment) == 0)
| 0 | ||||||||||||||||||||||||
| 1149 | return EINVAL; never executed: return 22 ; | 0 | ||||||||||||||||||||||||
| 1150 | - | |||||||||||||||||||||||||
| 1151 | mem = internal_memalign (alignment, size, (char *)0, 0, 0); | - | ||||||||||||||||||||||||
| 1152 | if (mem != 0)
| 0 | ||||||||||||||||||||||||
| 1153 | { | - | ||||||||||||||||||||||||
| 1154 | *memptr = mem; | - | ||||||||||||||||||||||||
| 1155 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 1156 | } | - | ||||||||||||||||||||||||
| 1157 | return ENOMEM; never executed: return 12 ; | 0 | ||||||||||||||||||||||||
| 1158 | } | - | ||||||||||||||||||||||||
| 1159 | - | |||||||||||||||||||||||||
| 1160 | size_t | - | ||||||||||||||||||||||||
| 1161 | malloc_usable_size (mem) | - | ||||||||||||||||||||||||
| 1162 | void *mem; | - | ||||||||||||||||||||||||
| 1163 | { | - | ||||||||||||||||||||||||
| 1164 | register union mhead *p; | - | ||||||||||||||||||||||||
| 1165 | register char *ap; | - | ||||||||||||||||||||||||
| 1166 | register int maxbytes; | - | ||||||||||||||||||||||||
| 1167 | - | |||||||||||||||||||||||||
| 1168 | - | |||||||||||||||||||||||||
| 1169 | if ((ap = (char *)mem) == 0)
| 0 | ||||||||||||||||||||||||
| 1170 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
| 1171 | - | |||||||||||||||||||||||||
| 1172 | /* Find the true start of the memory block to discover which bin */ | - | ||||||||||||||||||||||||
| 1173 | p = (union mhead *) ap - 1; | - | ||||||||||||||||||||||||
| 1174 | if (p->mh_alloc == ISMEMALIGN)
| 0 | ||||||||||||||||||||||||
| 1175 | { | - | ||||||||||||||||||||||||
| 1176 | ap -= p->mh_nbytes; | - | ||||||||||||||||||||||||
| 1177 | p = (union mhead *) ap - 1; | - | ||||||||||||||||||||||||
| 1178 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1179 | - | |||||||||||||||||||||||||
| 1180 | /* XXX - should we return 0 if ISFREE? */ | - | ||||||||||||||||||||||||
| 1181 | maxbytes = binsize(p->mh_index); | - | ||||||||||||||||||||||||
| 1182 | - | |||||||||||||||||||||||||
| 1183 | /* So the usable size is the maximum number of bytes in the bin less the | - | ||||||||||||||||||||||||
| 1184 | malloc overhead */ | - | ||||||||||||||||||||||||
| 1185 | maxbytes -= MOVERHEAD + MSLOP; | - | ||||||||||||||||||||||||
| 1186 | return (maxbytes); never executed: return (maxbytes); | 0 | ||||||||||||||||||||||||
| 1187 | } | - | ||||||||||||||||||||||||
| 1188 | - | |||||||||||||||||||||||||
| 1189 | #if !defined (NO_VALLOC) | - | ||||||||||||||||||||||||
| 1190 | /* This runs into trouble with getpagesize on HPUX, and Multimax machines. | - | ||||||||||||||||||||||||
| 1191 | Patching out seems cleaner than the ugly fix needed. */ | - | ||||||||||||||||||||||||
| 1192 | static PTR_T | - | ||||||||||||||||||||||||
| 1193 | internal_valloc (size, file, line, flags) | - | ||||||||||||||||||||||||
| 1194 | size_t size; | - | ||||||||||||||||||||||||
| 1195 | const char *file; | - | ||||||||||||||||||||||||
| 1196 | int line, flags; | - | ||||||||||||||||||||||||
| 1197 | { | - | ||||||||||||||||||||||||
| 1198 | return internal_memalign (getpagesize (), size, file, line, flags|MALLOC_INTERNAL); never executed: return internal_memalign (getpagesize (), size, file, line, flags|0x02); | 0 | ||||||||||||||||||||||||
| 1199 | } | - | ||||||||||||||||||||||||
| 1200 | #endif /* !NO_VALLOC */ | - | ||||||||||||||||||||||||
| 1201 | - | |||||||||||||||||||||||||
| 1202 | #ifndef NO_CALLOC | - | ||||||||||||||||||||||||
| 1203 | static PTR_T | - | ||||||||||||||||||||||||
| 1204 | internal_calloc (n, s, file, line, flags) | - | ||||||||||||||||||||||||
| 1205 | size_t n, s; | - | ||||||||||||||||||||||||
| 1206 | const char *file; | - | ||||||||||||||||||||||||
| 1207 | int line, flags; | - | ||||||||||||||||||||||||
| 1208 | { | - | ||||||||||||||||||||||||
| 1209 | size_t total; | - | ||||||||||||||||||||||||
| 1210 | PTR_T result; | - | ||||||||||||||||||||||||
| 1211 | - | |||||||||||||||||||||||||
| 1212 | total = n * s; | - | ||||||||||||||||||||||||
| 1213 | result = internal_malloc (total, file, line, flags|MALLOC_INTERNAL); | - | ||||||||||||||||||||||||
| 1214 | if (result)
| 0-5936 | ||||||||||||||||||||||||
| 1215 | memset (result, 0, total); executed 5936 times by 1 test: memset (result, 0, total);Executed by:
| 5936 | ||||||||||||||||||||||||
| 1216 | return result; executed 5936 times by 1 test: return result;Executed by:
| 5936 | ||||||||||||||||||||||||
| 1217 | } | - | ||||||||||||||||||||||||
| 1218 | - | |||||||||||||||||||||||||
| 1219 | static void | - | ||||||||||||||||||||||||
| 1220 | internal_cfree (p, file, line, flags) | - | ||||||||||||||||||||||||
| 1221 | PTR_T p; | - | ||||||||||||||||||||||||
| 1222 | const char *file; | - | ||||||||||||||||||||||||
| 1223 | int line, flags; | - | ||||||||||||||||||||||||
| 1224 | { | - | ||||||||||||||||||||||||
| 1225 | internal_free (p, file, line, flags|MALLOC_INTERNAL); | - | ||||||||||||||||||||||||
| 1226 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1227 | #endif /* !NO_CALLOC */ | - | ||||||||||||||||||||||||
| 1228 | - | |||||||||||||||||||||||||
| 1229 | #ifdef MALLOC_STATS | - | ||||||||||||||||||||||||
| 1230 | int | - | ||||||||||||||||||||||||
| 1231 | malloc_free_blocks (size) | - | ||||||||||||||||||||||||
| 1232 | int size; | - | ||||||||||||||||||||||||
| 1233 | { | - | ||||||||||||||||||||||||
| 1234 | int nfree; | - | ||||||||||||||||||||||||
| 1235 | register union mhead *p; | - | ||||||||||||||||||||||||
| 1236 | - | |||||||||||||||||||||||||
| 1237 | nfree = 0; | - | ||||||||||||||||||||||||
| 1238 | for (p = nextf[size]; p; p = CHAIN (p))
| 0 | ||||||||||||||||||||||||
| 1239 | nfree++; never executed: nfree++; | 0 | ||||||||||||||||||||||||
| 1240 | - | |||||||||||||||||||||||||
| 1241 | return nfree; never executed: return nfree; | 0 | ||||||||||||||||||||||||
| 1242 | } | - | ||||||||||||||||||||||||
| 1243 | #endif | - | ||||||||||||||||||||||||
| 1244 | - | |||||||||||||||||||||||||
| 1245 | #if defined (MALLOC_WRAPFUNCS) | - | ||||||||||||||||||||||||
| 1246 | PTR_T | - | ||||||||||||||||||||||||
| 1247 | sh_malloc (bytes, file, line) | - | ||||||||||||||||||||||||
| 1248 | size_t bytes; | - | ||||||||||||||||||||||||
| 1249 | const char *file; | - | ||||||||||||||||||||||||
| 1250 | int line; | - | ||||||||||||||||||||||||
| 1251 | { | - | ||||||||||||||||||||||||
| 1252 | return internal_malloc (bytes, file, line, MALLOC_WRAPPER); executed 2147483647 times by 1 test: return internal_malloc (bytes, file, line, 0x01);Executed by:
| Inf | ||||||||||||||||||||||||
| 1253 | } | - | ||||||||||||||||||||||||
| 1254 | - | |||||||||||||||||||||||||
| 1255 | PTR_T | - | ||||||||||||||||||||||||
| 1256 | sh_realloc (ptr, size, file, line) | - | ||||||||||||||||||||||||
| 1257 | PTR_T ptr; | - | ||||||||||||||||||||||||
| 1258 | size_t size; | - | ||||||||||||||||||||||||
| 1259 | const char *file; | - | ||||||||||||||||||||||||
| 1260 | int line; | - | ||||||||||||||||||||||||
| 1261 | { | - | ||||||||||||||||||||||||
| 1262 | return internal_realloc (ptr, size, file, line, MALLOC_WRAPPER); executed 92882 times by 1 test: return internal_realloc (ptr, size, file, line, 0x01);Executed by:
| 92882 | ||||||||||||||||||||||||
| 1263 | } | - | ||||||||||||||||||||||||
| 1264 | - | |||||||||||||||||||||||||
| 1265 | void | - | ||||||||||||||||||||||||
| 1266 | sh_free (mem, file, line) | - | ||||||||||||||||||||||||
| 1267 | PTR_T mem; | - | ||||||||||||||||||||||||
| 1268 | const char *file; | - | ||||||||||||||||||||||||
| 1269 | int line; | - | ||||||||||||||||||||||||
| 1270 | { | - | ||||||||||||||||||||||||
| 1271 | internal_free (mem, file, line, MALLOC_WRAPPER); | - | ||||||||||||||||||||||||
| 1272 | } executed 2147483647 times by 1 test: end of blockExecuted by:
| Inf | ||||||||||||||||||||||||
| 1273 | - | |||||||||||||||||||||||||
| 1274 | PTR_T | - | ||||||||||||||||||||||||
| 1275 | sh_memalign (alignment, size, file, line) | - | ||||||||||||||||||||||||
| 1276 | size_t alignment; | - | ||||||||||||||||||||||||
| 1277 | size_t size; | - | ||||||||||||||||||||||||
| 1278 | const char *file; | - | ||||||||||||||||||||||||
| 1279 | int line; | - | ||||||||||||||||||||||||
| 1280 | { | - | ||||||||||||||||||||||||
| 1281 | return internal_memalign (alignment, size, file, line, MALLOC_WRAPPER); never executed: return internal_memalign (alignment, size, file, line, 0x01); | 0 | ||||||||||||||||||||||||
| 1282 | } | - | ||||||||||||||||||||||||
| 1283 | - | |||||||||||||||||||||||||
| 1284 | #ifndef NO_CALLOC | - | ||||||||||||||||||||||||
| 1285 | PTR_T | - | ||||||||||||||||||||||||
| 1286 | sh_calloc (n, s, file, line) | - | ||||||||||||||||||||||||
| 1287 | size_t n, s; | - | ||||||||||||||||||||||||
| 1288 | const char *file; | - | ||||||||||||||||||||||||
| 1289 | int line; | - | ||||||||||||||||||||||||
| 1290 | { | - | ||||||||||||||||||||||||
| 1291 | return internal_calloc (n, s, file, line, MALLOC_WRAPPER); never executed: return internal_calloc (n, s, file, line, 0x01); | 0 | ||||||||||||||||||||||||
| 1292 | } | - | ||||||||||||||||||||||||
| 1293 | - | |||||||||||||||||||||||||
| 1294 | void | - | ||||||||||||||||||||||||
| 1295 | sh_cfree (mem, file, line) | - | ||||||||||||||||||||||||
| 1296 | PTR_T mem; | - | ||||||||||||||||||||||||
| 1297 | const char *file; | - | ||||||||||||||||||||||||
| 1298 | int line; | - | ||||||||||||||||||||||||
| 1299 | { | - | ||||||||||||||||||||||||
| 1300 | internal_cfree (mem, file, line, MALLOC_WRAPPER); | - | ||||||||||||||||||||||||
| 1301 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1302 | #endif | - | ||||||||||||||||||||||||
| 1303 | - | |||||||||||||||||||||||||
| 1304 | #ifndef NO_VALLOC | - | ||||||||||||||||||||||||
| 1305 | PTR_T | - | ||||||||||||||||||||||||
| 1306 | sh_valloc (size, file, line) | - | ||||||||||||||||||||||||
| 1307 | size_t size; | - | ||||||||||||||||||||||||
| 1308 | const char *file; | - | ||||||||||||||||||||||||
| 1309 | int line; | - | ||||||||||||||||||||||||
| 1310 | { | - | ||||||||||||||||||||||||
| 1311 | return internal_valloc (size, file, line, MALLOC_WRAPPER); never executed: return internal_valloc (size, file, line, 0x01); | 0 | ||||||||||||||||||||||||
| 1312 | } | - | ||||||||||||||||||||||||
| 1313 | #endif /* !NO_VALLOC */ | - | ||||||||||||||||||||||||
| 1314 | - | |||||||||||||||||||||||||
| 1315 | #endif /* MALLOC_WRAPFUNCS */ | - | ||||||||||||||||||||||||
| 1316 | - | |||||||||||||||||||||||||
| 1317 | /* Externally-available functions that call their internal counterparts. */ | - | ||||||||||||||||||||||||
| 1318 | - | |||||||||||||||||||||||||
| 1319 | PTR_T | - | ||||||||||||||||||||||||
| 1320 | malloc (size) | - | ||||||||||||||||||||||||
| 1321 | size_t size; | - | ||||||||||||||||||||||||
| 1322 | { | - | ||||||||||||||||||||||||
| 1323 | return internal_malloc (size, (char *)NULL, 0, 0); executed 116973081 times by 1 test: return internal_malloc (size, (char *) ((void *)0) , 0, 0);Executed by:
| 116973081 | ||||||||||||||||||||||||
| 1324 | } | - | ||||||||||||||||||||||||
| 1325 | - | |||||||||||||||||||||||||
| 1326 | PTR_T | - | ||||||||||||||||||||||||
| 1327 | realloc (mem, nbytes) | - | ||||||||||||||||||||||||
| 1328 | PTR_T mem; | - | ||||||||||||||||||||||||
| 1329 | size_t nbytes; | - | ||||||||||||||||||||||||
| 1330 | { | - | ||||||||||||||||||||||||
| 1331 | return internal_realloc (mem, nbytes, (char *)NULL, 0, 0); executed 4637049 times by 1 test: return internal_realloc (mem, nbytes, (char *) ((void *)0) , 0, 0);Executed by:
| 4637049 | ||||||||||||||||||||||||
| 1332 | } | - | ||||||||||||||||||||||||
| 1333 | - | |||||||||||||||||||||||||
| 1334 | void | - | ||||||||||||||||||||||||
| 1335 | free (mem) | - | ||||||||||||||||||||||||
| 1336 | PTR_T mem; | - | ||||||||||||||||||||||||
| 1337 | { | - | ||||||||||||||||||||||||
| 1338 | internal_free (mem, (char *)NULL, 0, 0); | - | ||||||||||||||||||||||||
| 1339 | } executed 115886356 times by 1 test: end of blockExecuted by:
| 115886356 | ||||||||||||||||||||||||
| 1340 | - | |||||||||||||||||||||||||
| 1341 | PTR_T | - | ||||||||||||||||||||||||
| 1342 | memalign (alignment, size) | - | ||||||||||||||||||||||||
| 1343 | size_t alignment; | - | ||||||||||||||||||||||||
| 1344 | size_t size; | - | ||||||||||||||||||||||||
| 1345 | { | - | ||||||||||||||||||||||||
| 1346 | return internal_memalign (alignment, size, (char *)NULL, 0, 0); never executed: return internal_memalign (alignment, size, (char *) ((void *)0) , 0, 0); | 0 | ||||||||||||||||||||||||
| 1347 | } | - | ||||||||||||||||||||||||
| 1348 | - | |||||||||||||||||||||||||
| 1349 | #ifndef NO_VALLOC | - | ||||||||||||||||||||||||
| 1350 | PTR_T | - | ||||||||||||||||||||||||
| 1351 | valloc (size) | - | ||||||||||||||||||||||||
| 1352 | size_t size; | - | ||||||||||||||||||||||||
| 1353 | { | - | ||||||||||||||||||||||||
| 1354 | return internal_valloc (size, (char *)NULL, 0, 0); never executed: return internal_valloc (size, (char *) ((void *)0) , 0, 0); | 0 | ||||||||||||||||||||||||
| 1355 | } | - | ||||||||||||||||||||||||
| 1356 | #endif | - | ||||||||||||||||||||||||
| 1357 | - | |||||||||||||||||||||||||
| 1358 | #ifndef NO_CALLOC | - | ||||||||||||||||||||||||
| 1359 | PTR_T | - | ||||||||||||||||||||||||
| 1360 | calloc (n, s) | - | ||||||||||||||||||||||||
| 1361 | size_t n, s; | - | ||||||||||||||||||||||||
| 1362 | { | - | ||||||||||||||||||||||||
| 1363 | return internal_calloc (n, s, (char *)NULL, 0, 0); executed 5936 times by 1 test: return internal_calloc (n, s, (char *) ((void *)0) , 0, 0);Executed by:
| 5936 | ||||||||||||||||||||||||
| 1364 | } | - | ||||||||||||||||||||||||
| 1365 | - | |||||||||||||||||||||||||
| 1366 | void | - | ||||||||||||||||||||||||
| 1367 | cfree (mem) | - | ||||||||||||||||||||||||
| 1368 | PTR_T mem; | - | ||||||||||||||||||||||||
| 1369 | { | - | ||||||||||||||||||||||||
| 1370 | internal_cfree (mem, (char *)NULL, 0, 0); | - | ||||||||||||||||||||||||
| 1371 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1372 | #endif | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |