Change Cache Storage callback to WeakPersistent instead of Persistent
This fixes a memory leak and renderer crash as described below. Change Cache Storage "open" method callback to have a WeakPersistent reference to CacheStorage to avoid a circular reference between them. Remove Persistent<CacheStorage> from callback for "delete" since it wasn't used. WebServiceWorkerCacheStorageImpl keeps the callback while waiting for mojo response from browser process which keeps CacheStorage alive, CacheStorage also has a reference to WebServiceWQorkerCacheStorage, which is implemented by WebServiceCacheStorageImpl, creating the circular reference, this situation leads to memory leak because those can't be garbage collected properly on some termination conditions, this leak in turn would cause renderer to crash when starting a new worker and trying to reuse pointer to address cleaned by Oilpan heap. When a worker is terminated with pending WithCacheCallback objects, the termination GC callback will access the Persistent handle. However, it will point to an object in a dead Oilpan heap and cause a segfault. Using a WeakPersistent is a workaround to prevent this crash, since the termination GC callback won't try to access it. In the future, Oilpan might be updated to handle this more gracefully see https://crbug.com/831117. The added test catches two conditions where renderer process was crashing: 1. When initializing Cache Storage after "close()". 2. Initializing Cache Storage before "close()" and issuing new calls, that trigger mojo after "close()". Bug: 831054 Change-Id: I6620d8107c00aed1c386c869dc1a793bc51d97fa Reviewed-on: https://chromium-review.googlesource.com/1011467 Commit-Queue: Luciano Pacheco (SYD) <lucmult@chromium.org> Reviewed-by:Daniel Cheng <dcheng@chromium.org> Reviewed-by:
Kentaro Hara <haraken@chromium.org> Cr-Commit-Position: refs/heads/master@{#551262}
Showing
Please register or sign in to comment