From c491cab4a03193764236338b3acfccff5884d3bc Mon Sep 17 00:00:00 2001 From: mseaborn Date: Tue, 1 Dec 2015 09:11:26 -0800 Subject: NaCl: Fix a file descriptor leak on Unix Before this change, the renderer process leaks a file descriptor every time a PNaCl translator process is launched or a (P)NaCl process runs without calling the ppapi_start() API. There was no leak on Windows, because client-side IPC::ChannelHandles fill out the "name" field rather than the "pipe.handle" field. BUG=302078 TEST=Run an invalid pexe repeatedly and manually inspect /proc/PID/fd of the renderer process. Review URL: https://codereview.chromium.org/1473513005 Cr-Commit-Position: refs/heads/master@{#362440} --- components/nacl/renderer/ppb_nacl_private_impl.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/components/nacl/renderer/ppb_nacl_private_impl.cc b/components/nacl/renderer/ppb_nacl_private_impl.cc index dfc7af8..07d20e2 100644 --- a/components/nacl/renderer/ppb_nacl_private_impl.cc +++ b/components/nacl/renderer/ppb_nacl_private_impl.cc @@ -66,6 +66,10 @@ #include "third_party/WebKit/public/web/WebSecurityOrigin.h" #include "third_party/WebKit/public/web/WebURLLoaderOptions.h" +#if defined(OS_WIN) +#include "base/win/scoped_handle.h" +#endif + namespace nacl { namespace { @@ -121,6 +125,17 @@ class NaClPluginInstance { public: NaClPluginInstance(PP_Instance instance): nexe_load_manager(instance), pexe_size(0) {} + ~NaClPluginInstance() { + // Make sure that we do not leak a file descriptor if the NaCl loader + // process never called ppapi_start() to initialize PPAPI. + if (instance_info) { +#if defined(OS_WIN) + base::win::ScopedHandle closer(instance_info->channel_handle.pipe.handle); +#else + base::ScopedFD closer(instance_info->channel_handle.socket.fd); +#endif + } + } NexeLoadManager nexe_load_manager; scoped_ptr json_manifest; -- cgit v1.1