Module: kamailio
Branch: master
Commit: 85a2523db649009332af059f6260ab4467b30360
URL:
https://github.com/kamailio/kamailio/commit/85a2523db649009332af059f6260ab4…
Author: S-P Chan <shihping.chan(a)gmail.com>
Committer: S-P Chan <shihping.chan(a)gmail.com>
Date: 2022-06-23T10:37:31+08:00
tls_wolfssl: reduce overhead per fragment to maintain 16 byte alignment
---
Modified: src/modules/tls_wolfssl/tls_init.c
---
Diff:
https://github.com/kamailio/kamailio/commit/85a2523db649009332af059f6260ab4…
Patch:
https://github.com/kamailio/kamailio/commit/85a2523db649009332af059f6260ab4…
---
diff --git a/src/modules/tls_wolfssl/tls_init.c b/src/modules/tls_wolfssl/tls_init.c
index 9993c4a3d5..5a468525c6 100644
--- a/src/modules/tls_wolfssl/tls_init.c
+++ b/src/modules/tls_wolfssl/tls_init.c
@@ -222,32 +222,28 @@ static const int MAX_ALIGN = __alignof__(max_align_t);
static void* ser_malloc(size_t size)
{
- char* ptr = shm_malloc(size + 2*MAX_ALIGN);
- int pad = MAX_ALIGN - ((long) ptr % MAX_ALIGN);
+ char* ptr = shm_malloc(size + MAX_ALIGN);
+ int pad = MAX_ALIGN - ((long) ptr % MAX_ALIGN); // 8 or 16 bytes
- *(size_t*)ptr = size;
-
- memset(ptr + MAX_ALIGN, pad, pad);
- return ptr + MAX_ALIGN + pad;
+ memset(ptr, pad, pad);
+ return ptr + pad;
}
static void* ser_realloc(void *ptr, size_t new_size)
{
if(!ptr) return ser_malloc(new_size);
- int pad = *((unsigned char*)ptr - 1);
- unsigned char *real_ptr = (unsigned char*)ptr - pad - MAX_ALIGN;
- int size = *(size_t*)real_ptr;
+ int pad = *((char*)ptr - 1); // 8 or 16 bytes
+ char *real_ptr = (char*)ptr - pad;
- char *new_ptr = shm_realloc(real_ptr, new_size+2*MAX_ALIGN);
- *(size_t*)new_ptr = new_size;
+ char *new_ptr = shm_realloc(real_ptr, new_size+MAX_ALIGN);
int new_pad = MAX_ALIGN - ((long) new_ptr % MAX_ALIGN);
if (new_pad != pad) {
- memmove(new_ptr + MAX_ALIGN + new_pad, new_ptr + MAX_ALIGN + pad, new_size);
- memset(new_ptr + MAX_ALIGN, new_pad, new_pad);
+ memmove(new_ptr + new_pad, new_ptr + pad, new_size);
+ memset(new_ptr, new_pad, new_pad);
}
- return new_ptr + MAX_ALIGN + new_pad;
+ return new_ptr + new_pad;
}
#endif /* LIBRESSL_VERSION_NUMBER */
@@ -255,7 +251,7 @@ static void ser_free(void *ptr)
{
if (ptr) {
int pad = *((unsigned char *)ptr - 1);
- shm_free((unsigned char*)ptr - pad - MAX_ALIGN);
+ shm_free((unsigned char*)ptr - pad);
}
}