From 895a1c03be41c3f021f021062246f7ccb3fa6631 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 19 Jan 2023 14:09:15 +0100 Subject: [PATCH] test: fix ThreadSanitizer data race warning Refs: https://github.com/libuv/libuv/issues/3681 --- test/test-ipc-send-recv.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/test-ipc-send-recv.c b/test/test-ipc-send-recv.c index 8a0e9708..1eba6dfa 100644 --- a/test/test-ipc-send-recv.c +++ b/test/test-ipc-send-recv.c @@ -76,10 +76,12 @@ static int write2_cb_called; static void alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { - /* we're not actually reading anything so a small buffer is okay */ - static char slab[8]; - buf->base = slab; - buf->len = sizeof(slab); + /* We're not actually reading anything so a small buffer is okay + * but it needs to be heap-allocated to appease TSan. + */ + buf->len = 8; + buf->base = malloc(buf->len); + ASSERT_NOT_NULL(buf->base); } @@ -91,6 +93,8 @@ static void recv_cb(uv_stream_t* handle, int r; union handles* recv; + free(buf->base); + pipe = (uv_pipe_t*) handle; ASSERT(pipe == &ctx.channel); @@ -304,6 +308,8 @@ static void read_cb(uv_stream_t* handle, union handles* recv; uv_write_t* write_req; + free(rdbuf->base); + if (nread == UV_EOF || nread == UV_ECONNABORTED) { return; }