perf_hooks: avoid memory leak on gc observer

Fixes: https://github.com/nodejs/node/issues/22229

PR-URL: https://github.com/nodejs/node/pull/22241
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yang Guo <yangguo@chromium.org>
Reviewed-By: George Adams <george.adams@uk.ibm.com>
This commit is contained in:
James M Snell 2018-08-10 09:58:20 -07:00 committed by George Adams
parent 2eb78e6dc3
commit f6eab1acf2
No known key found for this signature in database
GPG Key ID: 7B8D7E4421A0916D

View File

@ -272,6 +272,9 @@ void MarkGarbageCollectionEnd(Isolate* isolate,
v8::GCCallbackFlags flags,
void* data) {
Environment* env = static_cast<Environment*>(data);
// If no one is listening to gc performance entries, do not create them.
if (!env->performance_state()->observers[NODE_PERFORMANCE_ENTRY_TYPE_GC])
return;
GCPerformanceEntry* entry =
new GCPerformanceEntry(env,
static_cast<PerformanceGCKind>(type),