@cryptotaxi247 / netdata-1 / commits / 7f86425d2

fix crashes due to misaligned allocations (#13137)

Costa Tsaousis committed Jun 15, 2022 at 15:10 UTC 7f86425d20986feb2d210f87f7e5f2f52a9e802d
1 file changed +4 -2
libnetdata/onewayalloc/onewayalloc.c
+4 -2
@@ -1,7 +1,9 @@
1 #include "onewayalloc.h"
2
3 static size_t OWA_NATURAL_PAGE_SIZE = 0;
4 -static size_t OWA_NATURAL_ALIGNMENT = sizeof(int*);
4 +
5 +// https://www.gnu.org/software/libc/manual/html_node/Aligned-Memory-Blocks.html
6 +#define OWA_NATURAL_ALIGNMENT (sizeof(void *) * 2)
7
8 typedef struct owa_page {
9 size_t stats_pages;
@@ -36,7 +38,7 @@ static OWA_PAGE *onewayalloc_create_internal(OWA_PAGE *head, size_t size_hint) {
38
39 // make sure the new page will fit both the requested size
40 // and the OWA_PAGE structure at its beginning
39 - size_hint += sizeof(OWA_PAGE);
41 + size_hint += natural_alignment(sizeof(OWA_PAGE));
42
43 // prefer the user size if it is bigger than our size
44 if(size_hint > size) size = size_hint;