Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(843)

Unified Diff: ppapi/proxy/serialized_structs.cc

Issue 11312017: Avoid leaking SerializedHandles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/proxy/serialized_structs.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/proxy/serialized_structs.cc
diff --git a/ppapi/proxy/serialized_structs.cc b/ppapi/proxy/serialized_structs.cc
index 6622d4a4564a168c3b1b9cb14872d2ceca12b080..f83ae0b95c67e92ac42493c5fbd713235276e34c 100644
--- a/ppapi/proxy/serialized_structs.cc
+++ b/ppapi/proxy/serialized_structs.cc
@@ -5,11 +5,19 @@
#include "ppapi/proxy/serialized_structs.h"
#include "base/pickle.h"
+#include "base/platform_file.h"
+#include "base/shared_memory.h"
+#include "build/build_config.h"
+#include "ipc/ipc_platform_file.h"
#include "ppapi/c/dev/ppb_font_dev.h"
#include "ppapi/c/pp_file_info.h"
#include "ppapi/c/pp_rect.h"
#include "ppapi/shared_impl/var.h"
+#if defined(OS_NACL)
+#include <unistd.h>
+#endif
+
namespace ppapi {
namespace proxy {
@@ -106,6 +114,31 @@ bool SerializedHandle::IsHandleValid() const {
return false;
}
+void SerializedHandle::Close() {
+ if (IsHandleValid()) {
+ switch (type_) {
+ case INVALID:
+ NOTREACHED();
+ break;
+ case SHARED_MEMORY:
+ base::SharedMemory::CloseHandle(shm_handle_);
+ break;
+ case SOCKET:
+ case CHANNEL_HANDLE:
+ base::PlatformFile file =
+ IPC::PlatformFileForTransitToPlatformFile(descriptor_);
+#if !defined(OS_NACL)
+ base::ClosePlatformFile(file);
+#else
+ close(file);
+#endif
+ break;
+ // No default so the compiler will warn us if a new type is added.
+ }
+ }
+ *this = SerializedHandle();
+}
+
// static
bool SerializedHandle::WriteHeader(const Header& hdr, Pickle* pickle) {
if (!pickle->WriteInt(hdr.type))
« no previous file with comments | « ppapi/proxy/serialized_structs.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698