]>
Commit | Line | Data |
---|---|---|
675bd738 MK |
1 | '\" t |
2 | .\" Copyright (c) 2012 by Michael Kerrisk <mtk.manpages@gmail.com> | |
3 | .\" | |
93015253 | 4 | .\" %%%LICENSE_START(VERBATIM) |
675bd738 MK |
5 | .\" Permission is granted to make and distribute verbatim copies of this |
6 | .\" manual provided the copyright notice and this permission notice are | |
7 | .\" preserved on all copies. | |
8 | .\" | |
9 | .\" Permission is granted to copy and distribute modified versions of this | |
10 | .\" manual under the conditions for verbatim copying, provided that the | |
11 | .\" entire resulting derived work is distributed under the terms of a | |
12 | .\" permission notice identical to this one. | |
13 | .\" | |
14 | .\" Since the Linux kernel and libraries are constantly changing, this | |
15 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
16 | .\" responsibility for errors or omissions, or for damages resulting from | |
17 | .\" the use of the information contained herein. The author(s) may not | |
18 | .\" have taken the same level of care in the production of this manual, | |
19 | .\" which is licensed free of charge, as they might when working | |
20 | .\" professionally. | |
21 | .\" | |
22 | .\" Formatted or processed versions of this manual, if unaccompanied by | |
23 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 24 | .\" %%%LICENSE_END |
675bd738 | 25 | .\" |
c77eace5 | 26 | .TH MALLOPT 3 2014-07-08 "Linux" "Linux Programmer's Manual" |
675bd738 MK |
27 | .SH NAME |
28 | mallopt \- set memory allocation parameters | |
29 | .SH SYNOPSIS | |
30 | .B #include <malloc.h> | |
31 | ||
32 | .BI "int mallopt(int " param ", int " value ); | |
33 | .SH DESCRIPTION | |
34 | The | |
35 | .BR mallopt () | |
36 | function adjusts parameters that control the behavior of the | |
37 | memory-allocation functions (see | |
38 | .BR malloc (3)). | |
39 | The | |
40 | .IR param | |
41 | argument specifies the parameter to be modified, and | |
42 | .I value | |
43 | specifies the new value for that parameter. | |
44 | ||
45 | The following values can be specified for | |
46 | .IR param : | |
47 | .TP | |
9d116bd2 | 48 | .BR M_ARENA_MAX |
bb1ee72e MK |
49 | This is the maximum number of arenas that can be created. |
50 | The value of | |
51 | .B M_ARENA_TEST | |
52 | is not used when | |
53 | .B M_ARENA_MAX | |
54 | is defined. | |
55 | An arena represents a pool of memory that can be used by | |
56 | .BR malloc (3) | |
57 | (and similar) calls to service allocation requests. | |
58 | Arenas are thread safe and | |
59 | therefore may have multiple concurrent memory requests. | |
60 | The trade-off is between the number of threads and the number of arenas. | |
61 | The more arenas you have, the lower the per-thread contention, | |
9d116bd2 CD |
62 | but the higher the memory usage. |
63 | This parameter has been available since glibc 2.10 via | |
bb1ee72e MK |
64 | .BR \-\-enable\-experimental\-malloc , |
65 | and since glibc 2.15 by default. | |
9d116bd2 | 66 | In some versions of the allocator there was no limit on the number |
bb1ee72e MK |
67 | of created arenas (e.g., CentOS 5, RHEL 5). |
68 | ||
69 | When running programs on newer glibc versions, | |
70 | these applications may exhibit high contention when accessing arenas. | |
71 | In these cases, it may be beneficial to increase | |
72 | .B M_ARENA_MAX | |
73 | to match the number of threads. | |
74 | This is similar in behavior to strategies taken by tcmalloc and jemalloc | |
75 | (e.g., per-thread allocation pools). | |
9d116bd2 CD |
76 | .TP |
77 | .BR M_ARENA_TEST | |
bb1ee72e | 78 | This is the limit, in number of arenas created, at which the system |
9d116bd2 | 79 | configuration will be examined to evaluate a hard limit on the |
bb1ee72e MK |
80 | number of created arenas. |
81 | The computed limit is implementation-defined | |
82 | and is usually a multiple of the number of available cores. | |
83 | Once the limit is computed, the result is final and constrains | |
9d116bd2 | 84 | the total number of arenas. |
bb1ee72e MK |
85 | See |
86 | .B M_ARENA_MAX | |
87 | for the definition of an arena. | |
9d116bd2 | 88 | This parameter has been available since glibc 2.10 via |
bb1ee72e MK |
89 | .BR \-\-enable\-experimental\-malloc , |
90 | and since glibc 2.15 by default. | |
9d116bd2 | 91 | .TP |
675bd738 MK |
92 | .BR M_CHECK_ACTION |
93 | Setting this parameter controls how glibc responds when various kinds | |
94 | of programming errors are detected (e.g., freeing the same pointer twice). | |
95 | The 3 least significant bits (2, 1, and 0) of the value assigned | |
96 | to this parameter determine the glibc behavior, as follows: | |
97 | .RS | |
98 | .TP | |
99 | Bit 0 | |
100 | If this bit is set, then print a one-line message on | |
101 | .I stderr | |
102 | that provides details about the error. | |
103 | The message starts with the string "***\ glibc detected\ ***", | |
104 | followed by the program name, | |
105 | the name of the memory-allocation function in which the error was detected, | |
106 | a brief description of the error, | |
107 | and the memory address where the error was detected. | |
108 | .TP | |
109 | Bit 1 | |
110 | If this bit is set, then, | |
111 | after printing any error message specified by bit 0, | |
112 | the program is terminated by calling | |
113 | .BR abort (3). | |
114 | In glibc versions since 2.4, | |
115 | if bit 0 is also set, | |
116 | then, between printing the error message and aborting, | |
117 | the program also prints a stack trace in the manner of | |
118 | .BR backtrace (3), | |
119 | and prints the process's memory mapping in the style of | |
120 | .IR /proc/[pid]/maps | |
121 | (see | |
122 | .BR proc (5)). | |
123 | .TP | |
124 | Bit 2 (since glibc 2.4) | |
125 | This bit has an effect only if bit 0 is also set. | |
126 | If this bit is set, | |
127 | then the one-line message describing the error is simplified | |
128 | to contain just the name of the function where the error | |
129 | was detected and the brief description of the error. | |
130 | .RE | |
131 | .IP | |
132 | The remaining bits in | |
133 | .I value | |
134 | are ignored. | |
135 | .IP | |
136 | Combining the above details, | |
137 | the following numeric values are meaningful for | |
138 | .BR M_CHECK_ACTION : | |
139 | .RS 12 | |
140 | .IP 0 3 | |
141 | Ignore error conditions; continue execution (with undefined results). | |
142 | .IP 1 | |
143 | Print a detailed error message and continue execution. | |
144 | .IP 2 | |
145 | Abort the program. | |
146 | .IP 3 | |
147 | Print detailed error message, stack trace, and memory mappings, | |
148 | and abort the program. | |
149 | .IP 5 | |
150 | Print a simple error message and continue execution. | |
151 | .IP 7 | |
152 | Print simple error message, stack trace, and memory mappings, | |
153 | and abort the program. | |
154 | .RE | |
155 | .IP | |
156 | Since glibc 2.3.4, the default value for the | |
157 | .BR M_CHECK_ACTION | |
158 | parameter is 3. | |
159 | In glibc version 2.3.3 and earlier, the default value is 1. | |
160 | .IP | |
161 | Using a nonzero | |
162 | .B M_CHECK_ACTION | |
163 | value can be useful because otherwise a crash may happen much later, | |
164 | and the true cause of the problem is then very hard to track down. | |
165 | .TP | |
166 | .BR M_MMAP_MAX | |
167 | .\" The following text adapted from comments in the glibc source: | |
168 | This parameter specifies the maximum number of allocation requests that | |
169 | may be simultaneously serviced using | |
170 | .BR mmap (2). | |
171 | This parameter exists because some systems have a limited number | |
172 | of internal tables for use by | |
173 | .BR mmap (2), | |
174 | and using more than a few of them may degrade performance. | |
175 | .IP | |
176 | The default value is 65,536, | |
177 | a value which has no special significance and | |
178 | which servers only as a safeguard. | |
179 | Setting this parameter to 0 disables the use of | |
180 | .BR mmap (2) | |
181 | for servicing large allocation requests. | |
182 | .TP | |
183 | .BR M_MMAP_THRESHOLD | |
184 | For allocations greater than or equal to the limit specified (in bytes) by | |
185 | .BR M_MMAP_THRESHOLD | |
186 | that can't be satisfied from the free list, | |
187 | the memory-allocation functions employ | |
188 | .BR mmap (2) | |
189 | instead of increasing the program break using | |
190 | .BR sbrk (2). | |
191 | .IP | |
192 | Allocating memory using | |
193 | .BR mmap (2) | |
194 | has the significant advantage that the allocated memory blocks | |
195 | can always be independently released back to the system. | |
196 | (By contrast, | |
197 | the heap can be trimmed only if memory is freed at the top end.) | |
198 | On the other hand, there are some disadvantages to the use of | |
199 | .BR mmap (2): | |
200 | deallocated space is not placed on the free list | |
201 | for reuse by later allocations; | |
202 | memory may be wasted because | |
203 | .BR mmap (2) | |
204 | allocations must be page-aligned; | |
205 | and the kernel must perform the expensive task of zeroing out | |
206 | memory allocated via | |
207 | .BR mmap (2). | |
208 | Balancing these factors leads to a default setting of 128*1024 for the | |
209 | .BR M_MMAP_THRESHOLD | |
210 | parameter. | |
211 | .IP | |
212 | The lower limit for this parameter is 0. | |
213 | The upper limit is | |
214 | .BR DEFAULT_MMAP_THRESHOLD_MAX : | |
215 | 512*1024 on 32-bit systems or | |
216 | .IR 4*1024*1024*sizeof(long) | |
217 | on 64-bit systems. | |
218 | .IP | |
219 | .IR Note: | |
220 | Nowadays, glibc uses a dynamic mmap threshold by default. | |
221 | The initial value of the threshold is 128*1024, | |
222 | but when blocks larger than the current threshold and less than or equal to | |
223 | .BR DEFAULT_MMAP_THRESHOLD_MAX | |
224 | are freed, | |
1b0892e8 | 225 | the threshold is adjusted upward to the size of the freed block. |
675bd738 MK |
226 | When dynamic mmap thresholding is in effect, |
227 | the threshold for trimming the heap is also dynamically adjusted | |
228 | to be twice the dynamic mmap threshold. | |
229 | Dynamic adjustment of the mmap threshold is disabled if any of the | |
230 | .BR M_TRIM_THRESHOLD , | |
231 | .BR M_TOP_PAD , | |
232 | .BR M_MMAP_THRESHOLD , | |
233 | or | |
234 | .BR M_MMAP_MAX | |
235 | parameters is set. | |
236 | .TP | |
237 | .BR M_MXFAST " (since glibc 2.3)" | |
238 | .\" The following text adapted from comments in the glibc sources: | |
239 | Set the upper limit for memory allocation requests that are satisfied | |
240 | using "fastbins". | |
241 | (The measurement unit for this parameter is bytes.) | |
242 | Fastbins are storage areas that hold deallocated blocks of memory | |
243 | of the same size without merging adjacent free blocks. | |
244 | Subsequent reallocation of blocks of the same size can be handled | |
245 | very quickly by allocating from the fastbin, | |
246 | although memory fragmentation and the overall memory footprint | |
247 | of the program can increase. | |
248 | The default value for this parameter is | |
249 | .IR "64*sizeof(size_t)/4" | |
250 | (i.e., 64 on 32-bit architectures). | |
251 | The range for this parameter is 0 to | |
252 | .IR "80*sizeof(size_t)/4" . | |
253 | Setting | |
254 | .B M_MXFAST | |
255 | to 0 disables the use of fastbins. | |
256 | .TP | |
257 | .BR M_PERTURB " (since glibc 2.4)" | |
258 | If this parameter is set to a nonzero value, | |
259 | then bytes of allocated memory (other than allocations via | |
260 | .BR calloc (3)) | |
261 | are initialized to the complement of the value | |
262 | in the least significant byte of | |
263 | .IR value , | |
264 | and when allocated memory is released using | |
265 | .BR free (3), | |
528db023 | 266 | the freed bytes are set to the least significant byte of |
675bd738 MK |
267 | .IR value . |
268 | This can be useful for detecting errors where programs | |
269 | incorrectly rely on allocated memory being initialized to zero, | |
270 | or reuse values in memory that has already been freed. | |
271 | .TP | |
272 | .BR M_TOP_PAD | |
273 | This parameter defines the amount of padding to employ when calling | |
274 | .BR sbrk (2) | |
275 | to modify the program break. | |
276 | (The measurement unit for this parameter is bytes.) | |
277 | This parameter has an effect in the following circumstances: | |
278 | .RS | |
279 | .IP * 3 | |
280 | When the program break is increased, then | |
281 | .BR M_TOP_PAD | |
282 | bytes are added to the | |
283 | .BR sbrk (2) | |
284 | request. | |
285 | .IP * | |
286 | When the heap is trimmed as a consequence of calling | |
287 | .BR free (3) | |
288 | (see the discussion of | |
289 | .BR M_TRIM_THRESHOLD ) | |
290 | this much free space is preserved at the top of the heap. | |
291 | .RE | |
292 | .IP | |
293 | In either case, | |
294 | the amount of padding is always rounded to a system page boundary. | |
295 | .IP | |
296 | Modifying | |
297 | .BR M_TOP_PAD | |
298 | is a trade-off between increasing the number of system calls | |
299 | (when the parameter is set low) | |
300 | and wasting unused memory at the top of the heap | |
301 | (when the parameter is set high). | |
302 | .IP | |
303 | The default value for this parameter is 128*1024. | |
304 | .\" DEFAULT_TOP_PAD in glibc source | |
305 | .TP | |
306 | .BR M_TRIM_THRESHOLD | |
307 | When the amount of contiguous free memory at the top of the heap | |
308 | grows sufficiently large, | |
309 | .BR free (3) | |
310 | employs | |
311 | .BR sbrk (2) | |
312 | to release this memory back to the system. | |
313 | (This can be useful in programs that continue to execute for | |
314 | a long period after freeing a significant amount of memory.) | |
315 | The | |
316 | .BR M_TRIM_THRESHOLD | |
317 | parameter specifies the minimum size (in bytes) that | |
318 | this block of memory must reach before | |
319 | .BR sbrk (2) | |
320 | is used to trim the heap. | |
321 | .IP | |
322 | The default value for this parameter is 128*1024. | |
323 | Setting | |
324 | .BR M_TRIM_THRESHOLD | |
325 | to \-1 disables trimming completely. | |
326 | .IP | |
327 | Modifying | |
328 | .BR M_TRIM_THRESHOLD | |
329 | is a trade-off between increasing the number of system calls | |
330 | (when the parameter is set low) | |
331 | and wasting unused memory at the top of the heap | |
332 | (when the parameter is set high). | |
9d116bd2 | 333 | |
c634028a | 334 | .SS Environment variables |
675bd738 MK |
335 | A number of environment variables can be defined |
336 | to modify some of the same parameters as are controlled by | |
337 | .BR mallopt (). | |
338 | Using these variables has the advantage that the source code | |
339 | of the program need not be changed. | |
340 | To be effective, these variables must be defined before the | |
341 | first call to a memory-allocation function. | |
342 | (If the same parameters are adjusted via | |
f5e1d420 | 343 | .BR mallopt (), |
675bd738 MK |
344 | then the |
345 | .BR mallopt () | |
346 | settings take precedence.) | |
347 | For security reasons, | |
348 | these variables are ignored in set-user-ID and set-group-ID programs. | |
349 | ||
350 | The environment variables are as follows | |
9d116bd2 CD |
351 | (note the trailing underscore at the end of the name of some variables): |
352 | .TP | |
353 | .BR MALLOC_ARENA_MAX | |
354 | Controls the same parameter as | |
355 | .BR mallopt () | |
356 | .BR M_ARENA_MAX . | |
357 | .TP | |
358 | .BR MALLOC_ARENA_TEST | |
359 | Controls the same parameter as | |
360 | .BR mallopt () | |
361 | .BR M_ARENA_TEST . | |
675bd738 MK |
362 | .TP |
363 | .BR MALLOC_CHECK_ | |
364 | This environment variable controls the same parameter as | |
365 | .BR mallopt () | |
366 | .BR M_CHECK_ACTION . | |
367 | If this variable is set to a nonzero value, | |
368 | then a special implementation of the memory-allocation functions is used. | |
369 | (This is accomplished using the | |
370 | .BR malloc_hook (3) | |
371 | feature.) | |
372 | This implementation performs additional error checking, | |
373 | but is slower | |
374 | .\" On glibc 2.12/x86, a simple malloc()+free() loop is about 70% slower | |
375 | .\" when MALLOC_CHECK_ was set. | |
376 | than the standard set of memory-allocation functions. | |
377 | (This implementation does not detect all possible errors; | |
378 | memory leaks can still occur.) | |
379 | .IP | |
380 | The value assigned to this environment variable should be a single digit, | |
381 | whose meaning is as described for | |
382 | .BR M_CHECK_ACTION . | |
383 | Any characters beyond the initial digit are ignored. | |
384 | .IP | |
385 | For security reasons, the effect of | |
386 | .BR MALLOC_CHECK_ | |
387 | is disabled by default for set-user-ID and set-group-ID programs. | |
388 | However, if the file | |
389 | .IR /etc/suid\-debug | |
390 | exists (the content of the file is irrelevant), then | |
391 | .BR MALLOC_CHECK_ | |
392 | also has an effect for set-user-ID and set-group-ID programs. | |
393 | .TP | |
394 | .BR MALLOC_MMAP_MAX_ | |
395 | Controls the same parameter as | |
396 | .BR mallopt () | |
397 | .BR M_MMAP_MAX . | |
398 | .TP | |
399 | .BR MALLOC_MMAP_THRESHOLD_ | |
400 | Controls the same parameter as | |
401 | .BR mallopt () | |
402 | .BR M_MMAP_THRESHOLD . | |
403 | .TP | |
404 | .BR MALLOC_PERTURB_ | |
405 | Controls the same parameter as | |
406 | .BR mallopt () | |
407 | .BR M_PERTURB . | |
408 | .TP | |
409 | .BR MALLOC_TRIM_THRESHOLD_ | |
410 | Controls the same parameter as | |
411 | .BR mallopt () | |
412 | .BR M_TRIM_THRESHOLD . | |
413 | .TP | |
414 | .BR MALLOC_TOP_PAD_ | |
415 | Controls the same parameter as | |
416 | .BR mallopt () | |
417 | .BR M_TOP_PAD . | |
418 | .SH RETURN VALUE | |
419 | On success, | |
420 | .BR mallopt () | |
421 | returns 1. | |
422 | On error, it returns 0. | |
423 | .SH ERRORS | |
424 | On error, | |
425 | .I errno | |
426 | is | |
427 | .I not | |
428 | set. | |
429 | .\" .SH VERSIONS | |
430 | .\" Available already in glibc 2.0, possibly earlier | |
431 | .SH CONFORMING TO | |
432 | This function is not specified by POSIX or the C standards. | |
433 | A similar function exists on many System V derivatives, | |
434 | but the range of values for | |
435 | .IR param | |
436 | varies across systems. | |
437 | The SVID defined options | |
438 | .BR M_MXFAST , | |
439 | .BR M_NLBLKS , | |
440 | .BR M_GRAIN , | |
441 | and | |
442 | .BR M_KEEP , | |
443 | but only the first of these is implemented in glibc. | |
444 | .\" .SH NOTES | |
445 | .SH BUGS | |
446 | Specifying an invalid value for | |
447 | .I param | |
448 | does not generate an error. | |
449 | ||
450 | A calculation error within the glibc implementation means that | |
451 | a call of the form: | |
bea08fec | 452 | .\" FIXME . This looks buggy: |
675bd738 MK |
453 | .\" setting the M_MXFAST limit rounds up: (s + SIZE_SZ) & ~MALLOC_ALIGN_MASK) |
454 | .\" malloc requests are rounded up: | |
455 | .\" (req) + SIZE_SZ + MALLOC_ALIGN_MASK) & ~MALLOC_ALIGN_MASK | |
456 | .\" http://sources.redhat.com/bugzilla/show_bug.cgi?id=12129 | |
457 | .nf | |
458 | ||
459 | mallopt(M_MXFAST, n) | |
460 | ||
461 | .fi | |
462 | does not result in fastbins being employed for all allocations of size up to | |
463 | .IR n . | |
464 | To ensure desired results, | |
465 | .I n | |
466 | should be rounded up to the next multiple greater than or equal to | |
467 | .IR (2k+1)*sizeof(size_t) , | |
468 | where | |
469 | .I k | |
470 | is an integer. | |
471 | .\" Bins are multiples of 2 * sizeof(size_t) + sizeof(size_t) | |
472 | ||
675bd738 MK |
473 | If |
474 | .BR mallopt () | |
475 | is used to set | |
476 | .BR M_PERTURB , | |
477 | then, as expected, the bytes of allocated memory are initialized | |
478 | to the complement of the byte in | |
479 | .IR value , | |
480 | and when that memory is freed, | |
481 | the bytes of the region are initialized to the byte specified in | |
482 | .IR value . | |
483 | However, there is an | |
484 | .RI off-by- sizeof(size_t) | |
485 | error in the implementation: | |
bea08fec | 486 | .\" FIXME . http://sources.redhat.com/bugzilla/show_bug.cgi?id=12140 |
675bd738 MK |
487 | instead of initializing precisely the block of memory |
488 | being freed by the call | |
489 | .IR free(p) , | |
490 | the block starting at | |
491 | .I p+sizeof(size_t) | |
492 | is initialized. | |
493 | .SH EXAMPLE | |
494 | The program below demonstrates the use of | |
495 | .BR M_CHECK_ACTION . | |
496 | If the program is supplied with an (integer) command-line argument, | |
497 | then that argument is used to set the | |
498 | .BR M_CHECK_ACTION | |
499 | parameter. | |
500 | The program then allocates a block of memory, | |
501 | and frees it twice (an error). | |
502 | ||
503 | The following shell session shows what happens when we run this program | |
504 | under glibc, with the default value for | |
505 | .BR M_CHECK_ACTION : | |
506 | .in +4n | |
507 | .nf | |
508 | ||
509 | $ \fB./a.out\fP | |
9f0977ff | 510 | main(): returned from first free() call |
675bd738 MK |
511 | *** glibc detected *** ./a.out: double free or corruption (top): 0x09d30008 *** |
512 | ======= Backtrace: ========= | |
513 | /lib/libc.so.6(+0x6c501)[0x523501] | |
514 | /lib/libc.so.6(+0x6dd70)[0x524d70] | |
515 | /lib/libc.so.6(cfree+0x6d)[0x527e5d] | |
7755958a | 516 | \&./a.out[0x80485db] |
675bd738 | 517 | /lib/libc.so.6(__libc_start_main+0xe7)[0x4cdce7] |
7755958a | 518 | \&./a.out[0x8048471] |
675bd738 MK |
519 | ======= Memory map: ======== |
520 | 001e4000\-001fe000 r\-xp 00000000 08:06 1083555 /lib/libgcc_s.so.1 | |
521 | 001fe000\-001ff000 r\-\-p 00019000 08:06 1083555 /lib/libgcc_s.so.1 | |
522 | [some lines omitted] | |
523 | b7814000\-b7817000 rw\-p 00000000 00:00 0 | |
524 | bff53000\-bff74000 rw\-p 00000000 00:00 0 [stack] | |
525 | Aborted (core dumped) | |
526 | .fi | |
527 | .in | |
528 | .PP | |
529 | The following runs show the results when employing other values for | |
6315c1b6 | 530 | .BR M_CHECK_ACTION : |
675bd738 MK |
531 | .PP |
532 | .in +4n | |
533 | .nf | |
534 | $ \fB./a.out 1\fP # Diagnose error and continue | |
535 | main(): returned from first free() call | |
536 | *** glibc detected *** ./a.out: double free or corruption (top): 0x09cbe008 *** | |
537 | main(): returned from second free() call | |
538 | $ \fB./a.out 2\fP # Abort without error message | |
539 | main(): returned from first free() call | |
540 | Aborted (core dumped) | |
541 | $ \fB./a.out 0\fP # Ignore error and continue | |
542 | main(): returned from first free() call | |
543 | main(): returned from second free() call | |
544 | .fi | |
545 | .in | |
546 | .PP | |
547 | The next run shows how to set the same parameter using the | |
548 | .B MALLOC_CHECK_ | |
549 | environment variable: | |
550 | .PP | |
551 | .in +4n | |
552 | .nf | |
553 | $ \fBMALLOC_CHECK_=1 ./a.out\fP | |
554 | main(): returned from first free() call | |
555 | *** glibc detected *** ./a.out: free(): invalid pointer: 0x092c2008 *** | |
556 | main(): returned from second free() call | |
557 | .fi | |
558 | .in | |
559 | .SS Program source | |
560 | \& | |
561 | .nf | |
562 | #include <malloc.h> | |
563 | #include <stdio.h> | |
564 | #include <stdlib.h> | |
565 | ||
566 | int | |
567 | main(int argc, char *argv[]) | |
568 | { | |
569 | char *p; | |
570 | ||
571 | if (argc > 1) { | |
927ad1fb MK |
572 | if (mallopt(M_CHECK_ACTION, atoi(argv[1])) != 1) { |
573 | fprintf(stderr, "mallopt() failed"); | |
675bd738 MK |
574 | exit(EXIT_FAILURE); |
575 | } | |
576 | } | |
577 | ||
675bd738 MK |
578 | p = malloc(1000); |
579 | if (p == NULL) { | |
580 | fprintf(stderr, "malloc() failed"); | |
581 | exit(EXIT_FAILURE); | |
582 | } | |
583 | ||
584 | free(p); | |
585 | printf("main(): returned from first free() call\\n"); | |
586 | ||
587 | free(p); | |
588 | printf("main(): returned from second free() call\\n"); | |
589 | ||
590 | exit(EXIT_SUCCESS); | |
591 | } | |
592 | .fi | |
593 | .SH SEE ALSO | |
594 | .ad l | |
595 | .nh | |
2a91a509 | 596 | .BR mmap (2), |
675bd738 MK |
597 | .BR sbrk (2), |
598 | .BR mallinfo (3), | |
599 | .BR malloc (3), | |
600 | .BR malloc_hook (3), | |
5ff479a4 | 601 | .BR malloc_info (3), |
9f6ec7b1 | 602 | .BR malloc_stats (3), |
16ecf309 | 603 | .BR malloc_trim (3), |
361c3c7f | 604 | .BR mcheck (3), |
675bd738 MK |
605 | .BR mtrace (3), |
606 | .BR posix_memalign (3) |