diff options
| author | otto <> | 2017-04-13 18:32:55 +0000 |
|---|---|---|
| committer | otto <> | 2017-04-13 18:32:55 +0000 |
| commit | 634f8a3898681ce8ed3d370044fb0d826c1f246d (patch) | |
| tree | 3a288a7b1dc6c5346a27f50bc19e963b0aa87efd /src/lib/libc/stdlib/malloc.3 | |
| parent | 782713206702b2595574c79609bfdcc640112028 (diff) | |
| download | openbsd-634f8a3898681ce8ed3d370044fb0d826c1f246d.tar.gz openbsd-634f8a3898681ce8ed3d370044fb0d826c1f246d.tar.bz2 openbsd-634f8a3898681ce8ed3d370044fb0d826c1f246d.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.3 | 29 |
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 , |
| 68 | and | 68 | and |
| 69 | .Fn realloc | 69 | .Fn realloc |
| 70 | allocate memory space. | 70 | allocate |
| 71 | .Em objects , | ||
| 72 | regions of memory to store values. | ||
| 71 | The | 73 | The |
| 72 | .Fn malloc | 74 | .Fn malloc |
| 73 | function allocates uninitialized space for an object of | 75 | function allocates uninitialized space for an object of |
| @@ -94,6 +96,12 @@ function changes the size of the object pointed to by | |||
| 94 | to | 96 | to |
| 95 | .Fa size | 97 | .Fa size |
| 96 | bytes and returns a pointer to the (possibly moved) object. | 98 | bytes and returns a pointer to the (possibly moved) object. |
| 99 | If | ||
| 100 | .Fa ptr | ||
| 101 | is not | ||
| 102 | .Dv NULL , | ||
| 103 | it must be a pointer returned by an earlier call to an allocation or | ||
| 104 | reallocation function that was not freed in between. | ||
| 97 | The contents of the object are unchanged up to the lesser | 105 | The contents of the object are unchanged up to the lesser |
| 98 | of the new and old sizes. | 106 | of the new and old sizes. |
| 99 | If the new size is larger, the value of the newly allocated portion | 107 | If the new size is larger, the value of the newly allocated portion |
| @@ -183,8 +191,7 @@ The | |||
| 183 | .Fn freezero | 191 | .Fn freezero |
| 184 | function is similar to the | 192 | function is similar to the |
| 185 | .Fn free | 193 | .Fn free |
| 186 | function except it ensures the memory being deallocated is explicitly | 194 | function except it ensures memory is explicitly discarded. |
| 187 | discarded. | ||
| 188 | If | 195 | If |
| 189 | .Fa ptr | 196 | .Fa ptr |
| 190 | is | 197 | is |
| @@ -196,9 +203,15 @@ is not | |||
| 196 | .Dv NULL , | 203 | .Dv NULL , |
| 197 | the | 204 | the |
| 198 | .Fa size | 205 | .Fa size |
| 199 | argument must be the size of the earlier allocation that returned | 206 | argument must be equal or smaller than the size of the earlier allocation |
| 200 | .Fa ptr , | 207 | that returned |
| 201 | otherwise the behaviour is undefined. | 208 | .Fa ptr . |
| 209 | .Fn freezero | ||
| 210 | guarantees the memory range starting at | ||
| 211 | .Fa ptr | ||
| 212 | with length | ||
| 213 | .Fa size | ||
| 214 | is discarded while deallocating the whole object originally allocated. | ||
| 202 | .Sh RETURN VALUES | 215 | .Sh RETURN VALUES |
| 203 | Upon successful completion, the allocation functions | 216 | Upon successful completion, the allocation functions |
| 204 | return a pointer to the allocated space; otherwise, a | 217 | return a pointer to the allocated space; otherwise, a |
