1 .\" Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
3 .\" @APPLE_LICENSE_HEADER_START@
5 .\" The contents of this file constitute Original Code as defined in and
6 .\" are subject to the Apple Public Source License Version 1.1 (the
7 .\" "License"). You may not use this file except in compliance with the
8 .\" License. Please obtain a copy of the License at
9 .\" http://www.apple.com/publicsource and read it before using this file.
11 .\" This Original Code and all software distributed under the License are
12 .\" distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
13 .\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
14 .\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
15 .\" FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
16 .\" License for the specific language governing rights and limitations
17 .\" under the License.
19 .\" @APPLE_LICENSE_HEADER_END@
69 functions allocate memory.
70 The allocated memory is aligned such that it can be used for any data type,
71 including AltiVec- and SSE-related types.
74 function frees allocations that were created via the preceding allocation
81 bytes of memory and returns a pointer to the allocated memory.
85 function contiguously allocates enough space for
89 bytes of memory each and returns a pointer to the allocated memory.
90 The allocated memory is filled with bytes of value zero.
96 bytes of memory and returns a pointer to the allocated memory.
97 The allocated memory is aligned on a page boundary.
101 function tries to change the size of the allocation pointed to by
107 If there is not enough room to enlarge the memory allocation pointed to by
110 creates a new allocation, copies as much of the old data pointed to by
112 as will fit to the new allocation, frees the old allocation, and returns a
113 pointer to the allocated memory.
119 is identical to a call to
130 a new, minimum sized object is allocated and the original object is freed.
131 When extending a region allocated with calloc(3), realloc(3) does not guarantee
132 that the additional memory is also zero-filled.
136 function is identical to the
138 function, except that it
139 will free the passed pointer when the requested memory cannot be allocated.
142 specific API designed to ease the problems with traditional coding styles
143 for realloc causing memory leaks in libraries.
147 function deallocates the memory allocation pointed to by
150 is a NULL pointer, no operation is performed.
159 functions return a pointer to allocated memory.
160 If there is an error, they return a
169 the input pointer is still valid if reallocation failed.
172 the input pointer will have been freed if reallocation failed.
176 function does not return a value.
177 .Sh DEBUGGING ALLOCATION ERRORS
178 A number of facilities are provided to aid in debugging allocation errors in
180 These facilities are primarily controlled via environment variables.
181 The recognized environment variables and their meanings are documented below.
183 The following environment variables change the behavior of the
184 allocation-related functions.
185 .Bl -tag -width ".Ev MallocStackLoggingNoCompact"
186 .It Ev MallocLogFile <f>
187 Create/append messages to the given file path
189 instead of writing to the standard error.
190 .It Ev MallocGuardEdges
191 If set, add a guard page before and after each large block.
192 .It Ev MallocDoNotProtectPrelude
193 If set, do not add a guard page before large blocks,
196 environment variable is set.
197 .It Ev MallocDoNotProtectPostlude
198 If set, do not add a guard page after large blocks,
201 environment variable is set.
202 .It Ev MallocStackLogging
203 If set, record all stacks, so that tools like
206 .It Ev MallocStackLoggingNoCompact
207 If set, record all stacks in a manner that is compatible with the
210 .It Ev MallocStackLoggingDirectory
211 If set, records stack logs to the directory specified instead of saving them to the default location (/tmp).
212 .It Ev MallocScribble
213 If set, fill memory that has been allocated with 0xaa bytes.
214 This increases the likelihood that a program making assumptions about the contents of
215 freshly allocated memory will fail.
216 Also if set, fill memory that has been deallocated with 0x55 bytes.
217 This increases the likelihood that a program will fail due to accessing memory
218 that is no longer allocated.
219 .It Ev MallocCheckHeapStart <s>
220 If set, specifies the number of allocations
222 to wait before begining periodic heap checks every
225 .Ev MallocCheckHeapEach .
227 .Ev MallocCheckHeapStart
229 .Ev MallocCheckHeapEach
230 is not specified, the default check repetition is 1000.
231 .It Ev MallocCheckHeapEach <n>
232 If set, run a consistency check on the heap every
235 .Ev MallocCheckHeapEach
236 is only meaningful if
237 .Ev MallocCheckHeapStart
239 .It Ev MallocCheckHeapSleep <t>
240 Sets the number of seconds to sleep (waiting for a debugger to attach) when
241 .Ev MallocCheckHeapStart
242 is set and a heap corruption is detected.
243 The default is 100 seconds.
244 Setting this to zero means not to sleep at all.
245 Setting this to a negative number means to sleep (for the positive number of
246 seconds) only the very first time a heap corruption is detected.
247 .It Ev MallocCheckHeapAbort <b>
249 .Ev MallocCheckHeapStart
250 is set and this is set to a non-zero value, causes
252 to be called if a heap corruption is detected, instead of any sleeping.
253 .It Ev MallocErrorAbort
256 to be called if an error was encountered in
262 on a pointer previously freed.
263 .It Ev MallocCorruptionAbort
267 but will not abort in out of memory conditions, making it more useful to catch
268 only those errors which will cause memory corruption.
269 MallocCorruptionAbort is always set on 64-bit processes.
271 If set, print a list of environment variables that are paid heed to by the
272 allocation-related functions, along with short descriptions.
273 The list should correspond to this documentation.
275 .Sh DIAGNOSTIC MESSAGES
278 .Xr malloc_history 1 ,
281 .Xr malloc_zone_malloc 3 ,
282 .Xr posix_memalign 3 ,