git: 4c22848d1a7e - stable/13 - rtld_malloc: add cp2op() helper
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 02 Aug 2023 00:37:17 UTC
The branch stable/13 has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=4c22848d1a7e3fc996adc0cb71e35d7be8b26ffb
commit 4c22848d1a7e3fc996adc0cb71e35d7be8b26ffb
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2023-07-22 04:24:03 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-08-02 00:36:40 +0000
rtld_malloc: add cp2op() helper
(cherry picked from commit 86c7368f2bcefeb257f7dc40e4296261b295a674)
---
libexec/rtld-elf/rtld_malloc.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/libexec/rtld-elf/rtld_malloc.c b/libexec/rtld-elf/rtld_malloc.c
index 45d3f743e348..3437f638d339 100644
--- a/libexec/rtld-elf/rtld_malloc.c
+++ b/libexec/rtld-elf/rtld_malloc.c
@@ -106,6 +106,12 @@ static int pagesz; /* page size */
* increasing order.
*/
+static union overhead *
+cp2op(void *cp)
+{
+ return ((union overhead *)((caddr_t)cp - sizeof(union overhead)));
+}
+
void *
__crt_malloc(size_t nbytes)
{
@@ -209,7 +215,7 @@ __crt_free(void *cp)
if (cp == NULL)
return;
- op = (union overhead *)((caddr_t)cp - sizeof (union overhead));
+ op = cp2op(cp);
if (op->ov_magic != MAGIC)
return; /* sanity */
size = op->ov_index;
@@ -227,7 +233,7 @@ __crt_realloc(void *cp, size_t nbytes)
if (cp == NULL)
return (__crt_malloc(nbytes));
- op = (union overhead *)((caddr_t)cp - sizeof (union overhead));
+ op = cp2op(cp);
if (op->ov_magic != MAGIC)
return (NULL); /* Double-free or bad argument */
i = op->ov_index;