Skip to content

Commit 899d468

Browse files
adierkingrokhinip
authored andcommitted
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. Signed-off-by: Kim Topley <[email protected]>
1 parent e27d0bf commit 899d468

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/io.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,8 +2478,14 @@ _dispatch_operation_deliver_data(dispatch_operation_t op,
24782478
if (op->direction == DOP_DIR_READ) {
24792479
if (op->buf_len) {
24802480
void *buf = op->buf;
2481+
#if defined(_WIN32)
2482+
// buf is allocated with _aligned_malloc()
2483+
data = dispatch_data_create(buf, op->buf_len, NULL,
2484+
^{ _aligned_free(buf); });
2485+
#else
24812486
data = dispatch_data_create(buf, op->buf_len, NULL,
24822487
DISPATCH_DATA_DESTRUCTOR_FREE);
2488+
#endif
24832489
op->buf = NULL;
24842490
op->buf_len = 0;
24852491
dispatch_data_t d = dispatch_data_create_concat(op->data, data);
File renamed without changes.

0 commit comments

Comments
 (0)