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 <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Corentin Wallez 2019-01-14 18:41:13 +00:00 committed by Commit Bot service account
parent 03f64292ad
commit 1a99f42c7d
1 changed files with 10 additions and 9 deletions

View File

@ -22,6 +22,7 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <map> #include <map>
#include <memory>
#include <vector> #include <vector>
namespace dawn_wire { namespace dawn_wire {
@ -334,7 +335,9 @@ namespace dawn_wire {
} }
{% endfor %} {% endfor %}
void OnMapReadAsyncCallback(dawnBufferMapAsyncStatus status, const void* ptr, MapUserdata* data) { void OnMapReadAsyncCallback(dawnBufferMapAsyncStatus status, const void* ptr, MapUserdata* userdata) {
std::unique_ptr<MapUserdata> data(userdata);
// Skip sending the callback if the buffer has already been destroyed. // Skip sending the callback if the buffer has already been destroyed.
auto* bufferData = mKnownBuffer.Get(data->bufferId); auto* bufferData = mKnownBuffer.Get(data->bufferId);
if (bufferData == nullptr || bufferData->serial != data->bufferSerial) { if (bufferData == nullptr || bufferData->serial != data->bufferSerial) {
@ -357,11 +360,11 @@ namespace dawn_wire {
void* dataAlloc = GetCmdSpace(data->size); void* dataAlloc = GetCmdSpace(data->size);
memcpy(dataAlloc, ptr, 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<MapUserdata> data(userdata);
// Skip sending the callback if the buffer has already been destroyed. // Skip sending the callback if the buffer has already been destroyed.
auto* bufferData = mKnownBuffer.Get(data->bufferId); auto* bufferData = mKnownBuffer.Get(data->bufferId);
if (bufferData == nullptr || bufferData->serial != data->bufferSerial) { if (bufferData == nullptr || bufferData->serial != data->bufferSerial) {
@ -381,11 +384,11 @@ namespace dawn_wire {
bufferData->mappedData = ptr; bufferData->mappedData = ptr;
bufferData->mappedDataSize = data->size; bufferData->mappedDataSize = data->size;
} }
delete data;
} }
void OnFenceCompletedValueUpdated(FenceCompletionUserdata* data) { void OnFenceCompletedValueUpdated(FenceCompletionUserdata* userdata) {
std::unique_ptr<FenceCompletionUserdata> data(userdata);
ReturnFenceUpdateCompletedValueCmd cmd; ReturnFenceUpdateCompletedValueCmd cmd;
cmd.fenceId = data->fenceId; cmd.fenceId = data->fenceId;
cmd.fenceSerial = data->fenceSerial; cmd.fenceSerial = data->fenceSerial;
@ -393,8 +396,6 @@ namespace dawn_wire {
auto allocCmd = static_cast<ReturnFenceUpdateCompletedValueCmd*>(GetCmdSpace(sizeof(cmd))); auto allocCmd = static_cast<ReturnFenceUpdateCompletedValueCmd*>(GetCmdSpace(sizeof(cmd)));
*allocCmd = cmd; *allocCmd = cmd;
delete data;
} }
{% set client_side_commands = ["FenceGetCompletedValue"] %} {% set client_side_commands = ["FenceGetCompletedValue"] %}