summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/malloc.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/stdlib/malloc.3')
-rw-r--r--src/lib/libc/stdlib/malloc.321
1 files changed, 9 insertions, 12 deletions
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3
index 2a636b88cc..2f99ea9b80 100644
--- a/src/lib/libc/stdlib/malloc.3
+++ b/src/lib/libc/stdlib/malloc.3
@@ -30,15 +30,15 @@
30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31.\" SUCH DAMAGE. 31.\" SUCH DAMAGE.
32.\" 32.\"
33.\" $OpenBSD: malloc.3,v 1.74 2014/04/21 13:17:32 deraadt Exp $ 33.\" $OpenBSD: malloc.3,v 1.75 2014/04/22 14:26:26 tedu Exp $
34.\" 34.\"
35.Dd $Mdocdate: April 21 2014 $ 35.Dd $Mdocdate: April 22 2014 $
36.Dt MALLOC 3 36.Dt MALLOC 3
37.Os 37.Os
38.Sh NAME 38.Sh NAME
39.Nm malloc , 39.Nm malloc ,
40.Nm calloc , 40.Nm calloc ,
41.Nm mallocarray , 41.Nm reallocarray ,
42.Nm realloc , 42.Nm realloc ,
43.Nm free , 43.Nm free ,
44.Nm cfree 44.Nm cfree
@@ -50,7 +50,7 @@
50.Ft void * 50.Ft void *
51.Fn calloc "size_t nmemb" "size_t size" 51.Fn calloc "size_t nmemb" "size_t size"
52.Ft void * 52.Ft void *
53.Fn mallocarray "size_t nmemb" "size_t size" 53.Fn reallocarray "void *ptr" "size_t nmemb" "size_t size"
54.Ft void * 54.Ft void *
55.Fn realloc "void *ptr" "size_t size" 55.Fn realloc "void *ptr" "size_t size"
56.Ft void 56.Ft void
@@ -96,10 +96,10 @@ if ((p = malloc(num * size)) == NULL)
96.Pp 96.Pp
97The multiplication may lead to an integer overflow, which can 97The multiplication may lead to an integer overflow, which can
98be avoided using the extension 98be avoided using the extension
99.Fn mallocarray , 99.Fn reallocarray ,
100as follows: 100as follows:
101.Bd -literal -offset indent 101.Bd -literal -offset indent
102if ((p = mallocarray(num, size)) == NULL) 102if ((p = reallocarray(NULL, num, size)) == NULL)
103 err(1, "malloc"); 103 err(1, "malloc");
104.Ed 104.Ed
105.Pp 105.Pp
@@ -125,6 +125,8 @@ objects, each of whose size is
125.Fa size . 125.Fa size .
126The space is initialized to zero. 126The space is initialized to zero.
127The use of 127The use of
128.Fn reallocarray
129or
128.Fn calloc 130.Fn calloc
129is strongly encouraged when allocating multiple sized objects 131is strongly encouraged when allocating multiple sized objects
130in order to avoid possible integer overflows. 132in order to avoid possible integer overflows.
@@ -309,11 +311,6 @@ malloc_options = "X";
309.Pp 311.Pp
310Note that this will cause code that is supposed to handle 312Note that this will cause code that is supposed to handle
311out-of-memory conditions gracefully to abort instead. 313out-of-memory conditions gracefully to abort instead.
312.It Cm Z
313.Dq Zero .
314Fill some junk into the area allocated (see
315.Cm J ) ,
316except for the exact length the user asked for, which is zeroed.
317.It Cm < 314.It Cm <
318.Dq Half the cache size . 315.Dq Half the cache size .
319Decrease the size of the free page cache by a factor of two. 316Decrease the size of the free page cache by a factor of two.
@@ -494,6 +491,6 @@ random.
494A rewrite by Otto Moerbeek introducing a new central data structure and more 491A rewrite by Otto Moerbeek introducing a new central data structure and more
495randomization appeared in 492randomization appeared in
496.Ox 4.4 . 493.Ox 4.4 .
497.Fn mallocarray 494.Fn reallocarray
498appeared in 495appeared in
499.Ox 5.6 . 496.Ox 5.6 .