[release/6.0] Fix memory leak in enqueue/dequeue of EventPipe callback data. (#58244)
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Fri, 27 Aug 2021 17:02:03 +0000 (10:02 -0700)
committerGitHub <noreply@github.com>
Fri, 27 Aug 2021 17:02:03 +0000 (10:02 -0700)
commit59f5157f759d1140972dd8b4fd0a0b5fbb039846
tree4699a48caa597dac87868e2cf83eb5c72a5188bf
parenta021027796a21ce547ded1dba93889e8f6353f67
[release/6.0] Fix memory leak in enqueue/dequeue of EventPipe callback data. (#58244)

* Fix memory leak in enqueue/dequeue of EventPipe callback data.

https://github.com/dotnet/runtime/pull/56104 made sure provider
callback data gets its own copy of filter data. This created a couple
of memory leaks when queue/dequeue the callback data since callback data
was not correctly freed in these scenarios leading to leaks of the copied
filter data.

Was detected running the manual EventPipe native unit tests on Windows
using its build in use of _CrtMemCheckpoint (only available in debug
builds) automatically detecting memory leaks.

Fix makes sure callback data is moved into queue on enqueue and moved
out in dequeue and that caller of dequeue make sure to
free returned callback data using ep_provider_callback_data_fini
when done using it. Doing a move instead of copy will also reduce
the number of allocations when enqueue/dequeue callback data in
provider callback queue.

* Fix build error.

Co-authored-by: lateralusX <lateralusx.github@gmail.com>
src/mono/mono/eventpipe/test/ep-provider-callback-dataqueue-tests.c
src/mono/mono/eventpipe/test/ep-tests.c
src/native/eventpipe/ep-config.c
src/native/eventpipe/ep-types.h
src/native/eventpipe/ep.c