summaryrefslogtreecommitdiffstats
path: root/libnetdata
diff options
context:
space:
mode:
authorCosta Tsaousis <costa@netdata.cloud>2022-06-15 15:10:57 +0300
committerGitHub <noreply@github.com>2022-06-15 15:10:57 +0300
commit7f86425d20986feb2d210f87f7e5f2f52a9e802d (patch)
tree649b1f8e9db8d3670a70c58873f6897feaff43f9 /libnetdata
parent8842a638334f57528c5e0d39283ec39f721844e3 (diff)
fix crashes due to misaligned allocations (#13137)
Diffstat (limited to 'libnetdata')
-rw-r--r--libnetdata/onewayalloc/onewayalloc.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/libnetdata/onewayalloc/onewayalloc.c b/libnetdata/onewayalloc/onewayalloc.c
index a048aebf6b..267e386341 100644
--- a/libnetdata/onewayalloc/onewayalloc.c
+++ b/libnetdata/onewayalloc/onewayalloc.c
@@ -1,7 +1,9 @@
#include "onewayalloc.h"
static size_t OWA_NATURAL_PAGE_SIZE = 0;
-static size_t OWA_NATURAL_ALIGNMENT = sizeof(int*);
+
+// https://www.gnu.org/software/libc/manual/html_node/Aligned-Memory-Blocks.html
+#define OWA_NATURAL_ALIGNMENT (sizeof(void *) * 2)
typedef struct owa_page {
size_t stats_pages;
@@ -36,7 +38,7 @@ static OWA_PAGE *onewayalloc_create_internal(OWA_PAGE *head, size_t size_hint) {
// make sure the new page will fit both the requested size
// and the OWA_PAGE structure at its beginning
- size_hint += sizeof(OWA_PAGE);
+ size_hint += natural_alignment(sizeof(OWA_PAGE));
// prefer the user size if it is bigger than our size
if(size_hint > size) size = size_hint;