From 370a43de831fac6dea27af3f2da745b7187ff6c5 Mon Sep 17 00:00:00 2001 From: David Scott Date: Mon, 23 Jan 2017 14:44:34 +0000 Subject: [PATCH] tap-vsockd: allocate payload separately for better alignment Previously we allocated `sizeof(struct ring) + size`. This patch allocates `sizeof(struct ring)` and then `size` for the payload separately. Hopefully the payload will be better aligned. Signed-off-by: David Scott --- alpine/packages/tap-vsockd/ring.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/alpine/packages/tap-vsockd/ring.c b/alpine/packages/tap-vsockd/ring.c index 2744d6974..fe7791d58 100644 --- a/alpine/packages/tap-vsockd/ring.c +++ b/alpine/packages/tap-vsockd/ring.c @@ -23,14 +23,18 @@ struct ring { int size; /* Maximum number of buffered bytes */ pthread_cond_t c; pthread_mutex_t m; - char data[]; + char *data; }; struct ring *ring_allocate(int size) { - struct ring *ring = (struct ring*)malloc(sizeof(struct ring) + size); + struct ring *ring = (struct ring*)malloc(sizeof(struct ring)); if (!ring) { - fatal("Failed to allocate ring buffer"); + fatal("Failed to allocate ring buffer metadata"); + } + ring->data = (char*)malloc(size); + if (!ring->data) { + fatal("Failed to allocate ring buffer data"); } int err = 0; if ((err = pthread_cond_init(&ring->c, NULL)) != 0) {