From 1a99f42c7dc6b7da25cc4e143b0b6af93bd36c4d Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Mon, 14 Jan 2019 18:41:13 +0000 Subject: [PATCH] WireServer: Wrap userdata in unique_ptr in callbacks This fixes a leak that was introduced in https://dawn-review.googlesource.com/c/dawn/+/3622 where the early return doesn't delete the userdata. BUG=chromium:921360 Change-Id: I500dd2b4fa02121e5c0278c5f6f83a30861815e4 Reviewed-on: https://dawn-review.googlesource.com/c/3942 Commit-Queue: Corentin Wallez Reviewed-by: Austin Eng --- generator/templates/dawn_wire/WireServer.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/generator/templates/dawn_wire/WireServer.cpp b/generator/templates/dawn_wire/WireServer.cpp index 49a9f7120d..e186a4252c 100644 --- a/generator/templates/dawn_wire/WireServer.cpp +++ b/generator/templates/dawn_wire/WireServer.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include namespace dawn_wire { @@ -334,7 +335,9 @@ namespace dawn_wire { } {% endfor %} - void OnMapReadAsyncCallback(dawnBufferMapAsyncStatus status, const void* ptr, MapUserdata* data) { + void OnMapReadAsyncCallback(dawnBufferMapAsyncStatus status, const void* ptr, MapUserdata* userdata) { + std::unique_ptr data(userdata); + // Skip sending the callback if the buffer has already been destroyed. auto* bufferData = mKnownBuffer.Get(data->bufferId); if (bufferData == nullptr || bufferData->serial != data->bufferSerial) { @@ -357,11 +360,11 @@ namespace dawn_wire { void* dataAlloc = GetCmdSpace(data->size); memcpy(dataAlloc, ptr, data->size); } - - delete data; } - void OnMapWriteAsyncCallback(dawnBufferMapAsyncStatus status, void* ptr, MapUserdata* data) { + void OnMapWriteAsyncCallback(dawnBufferMapAsyncStatus status, void* ptr, MapUserdata* userdata) { + std::unique_ptr data(userdata); + // Skip sending the callback if the buffer has already been destroyed. auto* bufferData = mKnownBuffer.Get(data->bufferId); if (bufferData == nullptr || bufferData->serial != data->bufferSerial) { @@ -381,11 +384,11 @@ namespace dawn_wire { bufferData->mappedData = ptr; bufferData->mappedDataSize = data->size; } - - delete data; } - void OnFenceCompletedValueUpdated(FenceCompletionUserdata* data) { + void OnFenceCompletedValueUpdated(FenceCompletionUserdata* userdata) { + std::unique_ptr data(userdata); + ReturnFenceUpdateCompletedValueCmd cmd; cmd.fenceId = data->fenceId; cmd.fenceSerial = data->fenceSerial; @@ -393,8 +396,6 @@ namespace dawn_wire { auto allocCmd = static_cast(GetCmdSpace(sizeof(cmd))); *allocCmd = cmd; - - delete data; } {% set client_side_commands = ["FenceGetCompletedValue"] %}