diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/stdlib/malloc.3 | 29 | ||||
| -rw-r--r-- | src/lib/libc/stdlib/malloc.c | 10 |
2 files changed, 26 insertions, 13 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 |
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index 07c73ca774..ecac7ddfe9 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: malloc.c,v 1.220 2017/04/10 05:45:02 otto Exp $ */ | 1 | /* $OpenBSD: malloc.c,v 1.221 2017/04/13 18:32:55 otto Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net> | 3 | * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net> |
| 4 | * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> | 4 | * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> |
| @@ -1340,15 +1340,15 @@ ofree(struct dir_info *argpool, void *p, int clear, int check, size_t argsz) | |||
| 1340 | uint32_t chunknum = | 1340 | uint32_t chunknum = |
| 1341 | find_chunknum(pool, r, p, 0); | 1341 | find_chunknum(pool, r, p, 0); |
| 1342 | 1342 | ||
| 1343 | if (info->bits[info->offset + chunknum] != | 1343 | if (info->bits[info->offset + chunknum] < |
| 1344 | argsz) | 1344 | argsz) |
| 1345 | wrterror(pool, "recorded old size %hu" | 1345 | wrterror(pool, "recorded old size %hu" |
| 1346 | " != %zu", | 1346 | " < %zu", |
| 1347 | info->bits[info->offset + chunknum], | 1347 | info->bits[info->offset + chunknum], |
| 1348 | argsz); | 1348 | argsz); |
| 1349 | } | 1349 | } |
| 1350 | } else if (argsz != sz - mopts.malloc_guard) | 1350 | } else if (sz - mopts.malloc_guard < argsz) |
| 1351 | wrterror(pool, "recorded old size %zu != %zu", | 1351 | wrterror(pool, "recorded old size %zu < %zu", |
| 1352 | sz - mopts.malloc_guard, argsz); | 1352 | sz - mopts.malloc_guard, argsz); |
| 1353 | } | 1353 | } |
| 1354 | if (sz > MALLOC_MAXCHUNK) { | 1354 | if (sz > MALLOC_MAXCHUNK) { |
