From b6a91ef5dfec14c6a92d62f2c516f1ac967e9522 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Fri, 5 Feb 2021 12:39:05 -0800 Subject: [PATCH] fix: clean up base::LinkedList in context_bridge::ObjectCache (#27630) base::LinkedList does not delete its members on destruction. We need to manually ensure the linkedlist is empty when the ObjectCache is destroyed. Fixes #27039 Notes: Fixed memory leak when sending non-primitives over the context bridge --- shell/renderer/api/context_bridge/object_cache.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/shell/renderer/api/context_bridge/object_cache.cc b/shell/renderer/api/context_bridge/object_cache.cc index 8d111747e5ba..9646d5358a19 100644 --- a/shell/renderer/api/context_bridge/object_cache.cc +++ b/shell/renderer/api/context_bridge/object_cache.cc @@ -21,7 +21,15 @@ ObjectCachePairNode::ObjectCachePairNode(ObjectCachePair&& pair) { ObjectCachePairNode::~ObjectCachePairNode() = default; ObjectCache::ObjectCache() {} -ObjectCache::~ObjectCache() = default; +ObjectCache::~ObjectCache() { + for (const auto& pair : proxy_map_) { + while (!pair.second.empty()) { + ObjectCachePairNode* node = pair.second.head()->value(); + node->RemoveFromList(); + delete node; + } + } +} void ObjectCache::CacheProxiedObject(v8::Local from, v8::Local proxy_value) {