Skip to content

Commit 618c82d

Browse files
committed
io: free Windows operation data with _aligned_free()
`_dispatch_operation_perform()` uses `_aligned_malloc()` on Windows to allocate the data buffer. This means that we cannot use `DISPATCH_DATA_DESTRUCTOR_FREE` when we create the `dispatch_data_t`. Provide a custom destructor which correctly frees the buffer. Discovered while porting the dispatch_io test to Windows.
1 parent 7721660 commit 618c82d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/io.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,8 +2483,14 @@ _dispatch_operation_deliver_data(dispatch_operation_t op,
24832483
if (op->direction == DOP_DIR_READ) {
24842484
if (op->buf_len) {
24852485
void *buf = op->buf;
2486+
#if defined(_WIN32)
2487+
// buf is allocated with _aligned_malloc()
2488+
data = dispatch_data_create(buf, op->buf_len, NULL,
2489+
^{ _aligned_free(buf); });
2490+
#else
24862491
data = dispatch_data_create(buf, op->buf_len, NULL,
24872492
DISPATCH_DATA_DESTRUCTOR_FREE);
2493+
#endif
24882494
op->buf = NULL;
24892495
op->buf_len = 0;
24902496
dispatch_data_t d = dispatch_data_create_concat(op->data, data);

0 commit comments

Comments
 (0)