summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/malloc.3
diff options
context:
space:
mode:
authorotto <>2017-04-13 18:32:55 +0000
committerotto <>2017-04-13 18:32:55 +0000
commitc8e0fc6335c50b963cf789e50fa6dd954ee974b0 (patch)
tree3a288a7b1dc6c5346a27f50bc19e963b0aa87efd /src/lib/libc/stdlib/malloc.3
parent0f3f0734ef5aa0887305bde6762a8cbeb7d54695 (diff)
downloadopenbsd-c8e0fc6335c50b963cf789e50fa6dd954ee974b0.tar.gz
openbsd-c8e0fc6335c50b963cf789e50fa6dd954ee974b0.tar.bz2
openbsd-c8e0fc6335c50b963cf789e50fa6dd954ee974b0.zip
allow clearing less than allocated and document freezero(3) better
Diffstat (limited to 'src/lib/libc/stdlib/malloc.3')
-rw-r--r--src/lib/libc/stdlib/malloc.329
1 files changed, 21 insertions, 8 deletions
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3
index c09b4756fa..602787532e 100644
--- a/src/lib/libc/stdlib/malloc.3
+++ b/src/lib/libc/stdlib/malloc.3
@@ -30,9 +30,9 @@
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.111 2017/04/10 06:31:31 jmc Exp $ 33.\" $OpenBSD: malloc.3,v 1.112 2017/04/13 18:32:55 otto Exp $
34.\" 34.\"
35.Dd $Mdocdate: April 10 2017 $ 35.Dd $Mdocdate: April 13 2017 $
36.Dt MALLOC 3 36.Dt MALLOC 3
37.Os 37.Os
38.Sh NAME 38.Sh NAME
@@ -67,7 +67,9 @@ The standard functions
67.Fn calloc , 67.Fn calloc ,
68and 68and
69.Fn realloc 69.Fn realloc
70allocate memory space. 70allocate
71.Em objects ,
72regions of memory to store values.
71The 73The
72.Fn malloc 74.Fn malloc
73function allocates uninitialized space for an object of 75function allocates uninitialized space for an object of
@@ -94,6 +96,12 @@ function changes the size of the object pointed to by
94to 96to
95.Fa size 97.Fa size
96bytes and returns a pointer to the (possibly moved) object. 98bytes and returns a pointer to the (possibly moved) object.
99If
100.Fa ptr
101is not
102.Dv NULL ,
103it must be a pointer returned by an earlier call to an allocation or
104reallocation function that was not freed in between.
97The contents of the object are unchanged up to the lesser 105The contents of the object are unchanged up to the lesser
98of the new and old sizes. 106of the new and old sizes.
99If the new size is larger, the value of the newly allocated portion 107If the new size is larger, the value of the newly allocated portion
@@ -183,8 +191,7 @@ The
183.Fn freezero 191.Fn freezero
184function is similar to the 192function is similar to the
185.Fn free 193.Fn free
186function except it ensures the memory being deallocated is explicitly 194function except it ensures memory is explicitly discarded.
187discarded.
188If 195If
189.Fa ptr 196.Fa ptr
190is 197is
@@ -196,9 +203,15 @@ is not
196.Dv NULL , 203.Dv NULL ,
197the 204the
198.Fa size 205.Fa size
199argument must be the size of the earlier allocation that returned 206argument must be equal or smaller than the size of the earlier allocation
200.Fa ptr , 207that returned
201otherwise the behaviour is undefined. 208.Fa ptr .
209.Fn freezero
210guarantees the memory range starting at
211.Fa ptr
212with length
213.Fa size
214is discarded while deallocating the whole object originally allocated.
202.Sh RETURN VALUES 215.Sh RETURN VALUES
203Upon successful completion, the allocation functions 216Upon successful completion, the allocation functions
204return a pointer to the allocated space; otherwise, a 217return a pointer to the allocated space; otherwise, a