WireServer: on destruction, free all objects.

The fuzzer is correctly detecting leaks when an object is created but
not freed through the wire. It isn't clear yet if we want leftover
objects to be freed by the wire of by the Device itself, but in the
meantime we make the wire free them to fix the fuzzer issues.

BUG=dawn:59

Change-Id: Id7bff93e60a52e1f833f31b1eb3bfd30f8fe4215
Reviewed-on: https://dawn-review.googlesource.com/c/2566
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Corentin Wallez 2018-12-07 16:13:36 +00:00 committed by Commit Bot service account
parent 6f0e1f9d82
commit 1d2850a129
1 changed files with 26 additions and 0 deletions

View File

@ -145,6 +145,20 @@ namespace dawn_wire {
mKnown[id].allocated = false;
}
std::vector<T> AcquireAllHandles() {
std::vector<T> objects;
for (Data& data : mKnown) {
if (data.allocated && data.handle != nullptr) {
objects.push_back(data.handle);
data.valid = false;
data.allocated = false;
data.handle = nullptr;
}
}
return objects;
}
private:
std::vector<Data> mKnown;
};
@ -256,6 +270,18 @@ namespace dawn_wire {
procs.deviceSetErrorCallback(device, ForwardDeviceErrorToServer, userdata);
}
~Server() override {
//* Free all objects when the server is destroyed
{% for type in by_category["object"] if type.name.canonical_case() != "device" %}
{
std::vector<{{as_cType(type.name)}}> handles = mKnown{{type.name.CamelCase()}}.AcquireAllHandles();
for ({{as_cType(type.name)}} handle : handles) {
mProcs.{{as_varName(type.name, Name("release"))}}(handle);
}
}
{% endfor %}
}
void OnDeviceError(const char* message) {
ReturnDeviceErrorCallbackCmd cmd;
cmd.messageStrlen = std::strlen(message);