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

Unified Diff: util/mach/exception_ports.cc

Issue 1381023007: mac: Don’t leak send rights from ExceptionPorts::GetExceptionPorts() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 2 months 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 | « util/mach/exception_ports.h ('k') | util/mach/exception_ports_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/mach/exception_ports.cc
diff --git a/util/mach/exception_ports.cc b/util/mach/exception_ports.cc
index 2d85c1e67a4212600f8d656d41e443a1cc34e915..ef535b4cffbf56b5a96ab49c9dbfd128e332c5f5 100644
--- a/util/mach/exception_ports.cc
+++ b/util/mach/exception_ports.cc
@@ -19,6 +19,29 @@
namespace crashpad {
+ExceptionPorts::ExceptionHandlerVector::ExceptionHandlerVector()
+ : vector_() {
+}
+
+ExceptionPorts::ExceptionHandlerVector::~ExceptionHandlerVector() {
+ Deallocate();
+}
+
+void ExceptionPorts::ExceptionHandlerVector::clear() {
+ Deallocate();
+ vector_.clear();
+}
+
+void ExceptionPorts::ExceptionHandlerVector::Deallocate() {
+ for (ExceptionHandler& exception_handler : vector_) {
+ if (exception_handler.port != MACH_PORT_NULL) {
+ kern_return_t kr =
+ mach_port_deallocate(mach_task_self(), exception_handler.port);
+ MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) << "mach_port_deallocate";
+ }
+ }
+}
+
ExceptionPorts::ExceptionPorts(TargetType target_type, mach_port_t target_port)
: target_port_(target_port), dealloc_target_port_(false) {
switch (target_type) {
@@ -69,9 +92,8 @@ ExceptionPorts::~ExceptionPorts() {
}
}
-bool ExceptionPorts::GetExceptionPorts(
- exception_mask_t mask,
- std::vector<ExceptionHandler>* handlers) const {
+bool ExceptionPorts::GetExceptionPorts(exception_mask_t mask,
+ ExceptionHandlerVector* handlers) const {
// <mach/mach_types.defs> says that these arrays have room for 32 elements,
// despite EXC_TYPES_COUNT only being as low as 11 (in the 10.6 SDK), and
// later operating system versions have defined more exception types. The
« no previous file with comments | « util/mach/exception_ports.h ('k') | util/mach/exception_ports_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698