diff options
Diffstat (limited to 'man3/malloc.3')
-rw-r--r-- | man3/malloc.3 | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/man3/malloc.3 b/man3/malloc.3 index eee0b30..0ef2cc9 100644 --- a/man3/malloc.3 +++ b/man3/malloc.3 @@ -12,7 +12,7 @@ .\" FIXME . Review http://austingroupbugs.net/view.php?id=374 .\" to see what changes are required on this page. .\" -.TH malloc 3 2023-07-20 "Linux man-pages 6.05.01" +.TH malloc 3 2023-10-31 "Linux man-pages 6.7" .SH NAME malloc, free, calloc, realloc, reallocarray \- allocate and free dynamic memory .SH LIBRARY @@ -21,19 +21,19 @@ Standard C library .SH SYNOPSIS .nf .B #include <stdlib.h> -.PP +.P .BI "void *malloc(size_t " size ); .BI "void free(void *_Nullable " ptr ); .BI "void *calloc(size_t " nmemb ", size_t " size ); .BI "void *realloc(void *_Nullable " ptr ", size_t " size ); .BI "void *reallocarray(void *_Nullable " ptr ", size_t " nmemb ", size_t " size ); .fi -.PP +.P .RS -4 Feature Test Macro Requirements for glibc (see .BR feature_test_macros (7)): .RE -.PP +.P .BR reallocarray (): .nf Since glibc 2.29: @@ -87,7 +87,7 @@ is 0, then .BR calloc () returns a unique pointer value that can later be successfully passed to .BR free (). -.PP +.P If the multiplication of .I nmemb and @@ -99,7 +99,7 @@ By contrast, an integer overflow would not be detected in the following call to .BR malloc (), with the result that an incorrectly sized block of memory would be allocated: -.PP +.P .in +4n .EX malloc(nmemb * size); @@ -119,14 +119,14 @@ up to the minimum of the old and new sizes. If the new size is larger than the old size, the added memory will .I not be initialized. -.PP +.P If .I ptr is NULL, then the call is equivalent to .IR malloc(size) , for all values of .IR size . -.PP +.P If .I size is equal to zero, @@ -135,7 +135,7 @@ and is not NULL, then the call is equivalent to .I free(ptr) (but see "Nonportable behavior" for portability issues). -.PP +.P Unless .I ptr is NULL, it must have been returned by an earlier call to @@ -156,13 +156,13 @@ elements, each of which is .I size bytes. It is equivalent to the call -.PP +.P .in +4n .EX realloc(ptr, nmemb * size); .EE .in -.PP +.P However, unlike that .BR realloc () call, @@ -187,12 +187,12 @@ Attempting to allocate more than .B PTRDIFF_MAX bytes is considered an error, as an object that large could cause later pointer subtraction to overflow. -.PP +.P The .BR free () function returns no value, and preserves .IR errno . -.PP +.P The .BR realloc () and @@ -247,7 +247,6 @@ T{ .BR realloc () T} Thread safety MT-Safe .TE -.sp 1 .SH STANDARDS .TP .BR malloc () @@ -275,12 +274,12 @@ POSIX.1-2001, C89. .BR reallocarray () glibc 2.26. OpenBSD 5.6, FreeBSD 11.0. -.PP +.P .BR malloc () and related functions rejected sizes greater than .B PTRDIFF_MAX starting in glibc 2.30. -.PP +.P .BR free () preserved .I errno @@ -301,7 +300,7 @@ in .BR proc (5), and the Linux kernel source file .IR Documentation/vm/overcommit\-accounting.rst . -.PP +.P Normally, .BR malloc () allocates memory from the heap, and adjusts the size of the heap @@ -324,7 +323,7 @@ were unaffected by the resource limit; since Linux 4.7, this limit is also enforced for allocations performed using .BR mmap (2). -.PP +.P To avoid corruption in multithreaded applications, mutexes are used internally to protect the memory-management data structures employed by these functions. @@ -342,7 +341,7 @@ by the system or .BR mmap (2)), and managed with its own mutexes. -.PP +.P If your program uses a private memory allocator, it should do so by replacing .BR malloc (), @@ -364,11 +363,11 @@ fail without having a valid reason in .IR errno . Private memory allocators may also need to replace other glibc functions; see "Replacing malloc" in the glibc manual for details. -.PP +.P Crashes in memory allocators are almost always related to heap corruption, such as overflowing an allocated chunk or freeing the same pointer twice. -.PP +.P The .BR malloc () implementation is tunable via environment variables; see @@ -383,14 +382,14 @@ other implementations may return NULL without setting and portable POSIX programs should tolerate such behavior. See .BR realloc (3p). -.PP +.P POSIX requires memory allocators to set .I errno upon failure. However, the C standard does not require this, and applications portable to non-POSIX platforms should not assume this. -.PP +.P Portable programs should not use private memory allocators, as POSIX and the C standard do not allow replacement of .BR malloc (), @@ -455,7 +454,7 @@ my_mallocarray(size_t nmemb, size_t size) .BR mcheck (3), .BR mtrace (3), .BR posix_memalign (3) -.PP +.P For details of the GNU C library implementation, see .UR https://sourceware.org/glibc/wiki/MallocInternals .UE . |