Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- server/async.c | 15 +++++++++++++++ server/console.c | 7 +------ server/device.c | 6 +----- server/file.h | 2 ++ server/sock.c | 6 +----- 5 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/server/async.c b/server/async.c index e71dceb201b..17ef709f89e 100644 --- a/server/async.c +++ b/server/async.c @@ -361,6 +361,21 @@ void async_request_complete( struct async *async, unsigned int status, data_size async_terminate( async, status ); }
+/* complete a request-based async */ +void async_request_complete_alloc( struct async *async, unsigned int status, data_size_t result, + data_size_t out_size, const void *out_data ) +{ + void *out_data_copy = NULL; + + if (out_size && !(out_data_copy = memdup( out_data, out_size ))) + { + async_terminate( async, STATUS_NO_MEMORY ); + return; + } + + async_request_complete( async, status, result, out_size, out_data_copy ); +} + /* set the timeout of an async operation */ void async_set_timeout( struct async *async, timeout_t timeout, unsigned int status ) { diff --git a/server/console.c b/server/console.c index 94f7c37e7c5..3360f680448 100644 --- a/server/console.c +++ b/server/console.c @@ -1500,12 +1500,7 @@ DECL_HANDLER(get_next_console_request) { data_size_t out_size = min( iosb->out_size, get_req_data_size() ); data_size_t result = ioctl->code == IOCTL_CONDRV_WRITE_FILE ? iosb->in_size : out_size; - void *out_data; - - if (!out_size || (out_data = memdup( get_req_data(), out_size ))) - async_request_complete( async, status, result, out_size, out_data ); - else - async_terminate( async, STATUS_NO_MEMORY ); + async_request_complete_alloc( async, status, result, out_size, get_req_data() ); }
release_object( async ); diff --git a/server/device.c b/server/device.c index 96389a1459b..29b36845e68 100644 --- a/server/device.c +++ b/server/device.c @@ -385,12 +385,8 @@ static void set_irp_result( struct irp_call *irp, unsigned int status, irp->file = NULL; if (irp->async) { - void *out_data; - out_size = min( irp->iosb->out_size, out_size ); - if (out_size && !(out_data = memdup( out_data, out_size ))) - out_size = 0; - async_request_complete( irp->async, status, result, out_size, out_data ); + async_request_complete_alloc( irp->async, status, result, out_size, out_data ); release_object( irp->async ); irp->async = NULL; } diff --git a/server/file.h b/server/file.h index 1c019a0667e..8e42cd3704e 100644 --- a/server/file.h +++ b/server/file.h @@ -229,6 +229,8 @@ extern int async_waiting( struct async_queue *queue ); extern void async_terminate( struct async *async, unsigned int status ); extern void async_request_complete( struct async *async, unsigned int status, data_size_t result, data_size_t out_size, void *out_data ); +extern void async_request_complete_alloc( struct async *async, unsigned int status, data_size_t result, + data_size_t out_size, const void *out_data ); extern void async_wake_up( struct async_queue *queue, unsigned int status ); extern struct completion *fd_get_completion( struct fd *fd, apc_param_t *p_key ); extern void fd_copy_completion( struct fd *src, struct fd *dst ); diff --git a/server/sock.c b/server/sock.c index 00d5d47edff..1e31b806986 100644 --- a/server/sock.c +++ b/server/sock.c @@ -710,7 +710,6 @@ static void complete_async_accept( struct sock *sock, struct accept_req *req ) else { obj_handle_t handle; - void *out_data;
if (!(acceptsock = accept_socket( sock ))) { @@ -727,10 +726,7 @@ static void complete_async_accept( struct sock *sock, struct accept_req *req ) return; }
- if (!(out_data = malloc( sizeof(handle) ))) return; - - memcpy( out_data, &handle, sizeof(handle) ); - async_request_complete( req->async, STATUS_SUCCESS, 0, sizeof(handle), out_data ); + async_request_complete_alloc( req->async, STATUS_SUCCESS, 0, sizeof(handle), &handle ); } }