Don't leak blocks if GetCheckedHandle throws.

This commit is contained in:
Rolf Bjarne Kvinge 2018-08-01 15:06:55 +02:00
Родитель b539083d6d
Коммит def474d3ac
6 изменённых файлов: 85 добавлений и 34 удалений

Просмотреть файл

@ -109,10 +109,13 @@ namespace Network {
BlockLiteral *block_ptr_handler = &block_handler; BlockLiteral *block_ptr_handler = &block_handler;
block_handler.SetupBlockUnsafe (static_stateChangeHandler, stateHandler); block_handler.SetupBlockUnsafe (static_stateChangeHandler, stateHandler);
try {
nw_connection_set_state_changed_handler (GetCheckedHandle (), (void*) block_ptr_handler); nw_connection_set_state_changed_handler (GetCheckedHandle (), (void*) block_ptr_handler);
} finally {
block_handler.CleanupBlock (); block_handler.CleanupBlock ();
} }
} }
}
delegate void nw_connection_boolean_event_handler_t (IntPtr block, [MarshalAs(UnmanagedType.U1)] bool value); delegate void nw_connection_boolean_event_handler_t (IntPtr block, [MarshalAs(UnmanagedType.U1)] bool value);
static nw_connection_boolean_event_handler_t static_BooleanChangeHandler = TrampolineBooleanChangeHandler; static nw_connection_boolean_event_handler_t static_BooleanChangeHandler = TrampolineBooleanChangeHandler;
@ -141,10 +144,13 @@ namespace Network {
BlockLiteral *block_ptr_handler = &block_handler; BlockLiteral *block_ptr_handler = &block_handler;
block_handler.SetupBlockUnsafe (static_BooleanChangeHandler, callback); block_handler.SetupBlockUnsafe (static_BooleanChangeHandler, callback);
try {
nw_connection_set_viability_changed_handler (GetCheckedHandle (), (void*) block_ptr_handler); nw_connection_set_viability_changed_handler (GetCheckedHandle (), (void*) block_ptr_handler);
} finally {
block_handler.CleanupBlock (); block_handler.CleanupBlock ();
} }
} }
}
[DllImport (Constants.NetworkLibrary)] [DllImport (Constants.NetworkLibrary)]
static extern unsafe void nw_connection_set_better_path_available_handler (IntPtr handle, void *callback); static extern unsafe void nw_connection_set_better_path_available_handler (IntPtr handle, void *callback);
@ -162,10 +168,13 @@ namespace Network {
BlockLiteral *block_ptr_handler = &block_handler; BlockLiteral *block_ptr_handler = &block_handler;
block_handler.SetupBlockUnsafe (static_BooleanChangeHandler, callback); block_handler.SetupBlockUnsafe (static_BooleanChangeHandler, callback);
try {
nw_connection_set_better_path_available_handler (GetCheckedHandle (), (void*) block_ptr_handler); nw_connection_set_better_path_available_handler (GetCheckedHandle (), (void*) block_ptr_handler);
} finally {
block_handler.CleanupBlock (); block_handler.CleanupBlock ();
} }
} }
}
delegate void nw_connection_path_event_handler_t (IntPtr block, IntPtr path); delegate void nw_connection_path_event_handler_t (IntPtr block, IntPtr path);
static nw_connection_path_event_handler_t static_PathChanged = TrampolinePathChanged; static nw_connection_path_event_handler_t static_PathChanged = TrampolinePathChanged;
@ -191,10 +200,13 @@ namespace Network {
BlockLiteral *block_ptr_handler = &block_handler; BlockLiteral *block_ptr_handler = &block_handler;
block_handler.SetupBlockUnsafe (static_PathChanged, callback); block_handler.SetupBlockUnsafe (static_PathChanged, callback);
try {
nw_connection_set_path_changed_handler (GetCheckedHandle (), (void*) block_ptr_handler); nw_connection_set_path_changed_handler (GetCheckedHandle (), (void*) block_ptr_handler);
} finally {
block_handler.CleanupBlock (); block_handler.CleanupBlock ();
} }
} }
}
[DllImport (Constants.NetworkLibrary)] [DllImport (Constants.NetworkLibrary)]
static extern void nw_connection_set_queue (IntPtr handle, IntPtr queue); static extern void nw_connection_set_queue (IntPtr handle, IntPtr queue);
@ -302,10 +314,13 @@ namespace Network {
BlockLiteral *block_ptr_handler = &block_handler; BlockLiteral *block_ptr_handler = &block_handler;
block_handler.SetupBlockUnsafe (static_ReceiveCompletion, callback); block_handler.SetupBlockUnsafe (static_ReceiveCompletion, callback);
try {
nw_connection_receive (GetCheckedHandle (), minimumIncompleteLength, maximumLength, (void*) block_ptr_handler); nw_connection_receive (GetCheckedHandle (), minimumIncompleteLength, maximumLength, (void*) block_ptr_handler);
} finally {
block_handler.CleanupBlock (); block_handler.CleanupBlock ();
} }
} }
}
[BindingImpl (BindingImplOptions.Optimizable)] [BindingImpl (BindingImplOptions.Optimizable)]
public void ReceiveData (uint minimumIncompleteLength, uint maximumLength, NWConnectionReceiveDispatchDataCompletion callback) public void ReceiveData (uint minimumIncompleteLength, uint maximumLength, NWConnectionReceiveDispatchDataCompletion callback)
@ -318,10 +333,13 @@ namespace Network {
BlockLiteral *block_ptr_handler = &block_handler; BlockLiteral *block_ptr_handler = &block_handler;
block_handler.SetupBlockUnsafe (static_ReceiveCompletionDispatchData, callback); block_handler.SetupBlockUnsafe (static_ReceiveCompletionDispatchData, callback);
try {
nw_connection_receive (GetCheckedHandle (), minimumIncompleteLength, maximumLength, (void*) block_ptr_handler); nw_connection_receive (GetCheckedHandle (), minimumIncompleteLength, maximumLength, (void*) block_ptr_handler);
} finally {
block_handler.CleanupBlock (); block_handler.CleanupBlock ();
} }
} }
}
[DllImport (Constants.NetworkLibrary)] [DllImport (Constants.NetworkLibrary)]
static extern unsafe void nw_connection_receive_message (IntPtr handle, void *callback); static extern unsafe void nw_connection_receive_message (IntPtr handle, void *callback);
@ -337,10 +355,13 @@ namespace Network {
BlockLiteral *block_ptr_handler = &block_handler; BlockLiteral *block_ptr_handler = &block_handler;
block_handler.SetupBlockUnsafe (static_ReceiveCompletion, callback); block_handler.SetupBlockUnsafe (static_ReceiveCompletion, callback);
try {
nw_connection_receive_message (GetCheckedHandle (), (void*) block_ptr_handler); nw_connection_receive_message (GetCheckedHandle (), (void*) block_ptr_handler);
} finally {
block_handler.CleanupBlock (); block_handler.CleanupBlock ();
} }
} }
}
[BindingImpl (BindingImplOptions.Optimizable)] [BindingImpl (BindingImplOptions.Optimizable)]
public void ReceiveMessageData (NWConnectionReceiveDispatchDataCompletion callback) public void ReceiveMessageData (NWConnectionReceiveDispatchDataCompletion callback)
@ -353,10 +374,13 @@ namespace Network {
BlockLiteral *block_ptr_handler = &block_handler; BlockLiteral *block_ptr_handler = &block_handler;
block_handler.SetupBlockUnsafe (static_ReceiveCompletionDispatchData, callback); block_handler.SetupBlockUnsafe (static_ReceiveCompletionDispatchData, callback);
try {
nw_connection_receive_message (GetCheckedHandle (), (void*) block_ptr_handler); nw_connection_receive_message (GetCheckedHandle (), (void*) block_ptr_handler);
} finally {
block_handler.CleanupBlock (); block_handler.CleanupBlock ();
} }
} }
}
delegate void nw_connection_send_completion_t (IntPtr block, IntPtr error); delegate void nw_connection_send_completion_t (IntPtr block, IntPtr error);
static nw_connection_send_completion_t static_SendCompletion = TrampolineSendCompletion; static nw_connection_send_completion_t static_SendCompletion = TrampolineSendCompletion;
@ -424,10 +448,13 @@ namespace Network {
BlockLiteral *block_ptr_handler = &block_handler; BlockLiteral *block_ptr_handler = &block_handler;
block_handler.SetupBlockUnsafe (static_SendCompletion, callback); block_handler.SetupBlockUnsafe (static_SendCompletion, callback);
try {
LowLevelSend (GetCheckedHandle (), buffer, context.Handle, isComplete, block_ptr_handler); LowLevelSend (GetCheckedHandle (), buffer, context.Handle, isComplete, block_ptr_handler);
} finally {
block_handler.CleanupBlock (); block_handler.CleanupBlock ();
} }
} }
}
static IntPtr _nw_connection_send_idempotent_content; static IntPtr _nw_connection_send_idempotent_content;

Просмотреть файл

@ -182,10 +182,13 @@ namespace Network {
BlockLiteral *block_ptr_handler = &block_handler; BlockLiteral *block_ptr_handler = &block_handler;
block_handler.SetupBlockUnsafe (static_ProtocolIterator, callback); block_handler.SetupBlockUnsafe (static_ProtocolIterator, callback);
try {
nw_content_context_foreach_protocol_metadata (GetCheckedHandle (), (void*) block_ptr_handler); nw_content_context_foreach_protocol_metadata (GetCheckedHandle (), (void*) block_ptr_handler);
} finally {
block_handler.CleanupBlock (); block_handler.CleanupBlock ();
} }
} }
}
// //
// Use this as a parameter to NWConnection.Send's with all the default properties // Use this as a parameter to NWConnection.Send's with all the default properties

Просмотреть файл

@ -133,10 +133,13 @@ namespace Network {
BlockLiteral *block_ptr_handler = &block_handler; BlockLiteral *block_ptr_handler = &block_handler;
block_handler.SetupBlockUnsafe (static_ListenerStateChanged, callback); block_handler.SetupBlockUnsafe (static_ListenerStateChanged, callback);
try {
nw_listener_set_state_changed_handler (GetCheckedHandle (), (void*) block_ptr_handler); nw_listener_set_state_changed_handler (GetCheckedHandle (), (void*) block_ptr_handler);
} finally {
block_handler.CleanupBlock (); block_handler.CleanupBlock ();
} }
} }
}
delegate void nw_listener_new_connection_handler_t (IntPtr block, IntPtr connection); delegate void nw_listener_new_connection_handler_t (IntPtr block, IntPtr connection);
static nw_listener_new_connection_handler_t static_NewConnection = TrampolineNewConnection; static nw_listener_new_connection_handler_t static_NewConnection = TrampolineNewConnection;
@ -167,10 +170,13 @@ namespace Network {
BlockLiteral *block_ptr_handler = &block_handler; BlockLiteral *block_ptr_handler = &block_handler;
block_handler.SetupBlockUnsafe (static_NewConnection, callback); block_handler.SetupBlockUnsafe (static_NewConnection, callback);
try {
nw_listener_set_new_connection_handler (GetCheckedHandle (), (void*) block_ptr_handler); nw_listener_set_new_connection_handler (GetCheckedHandle (), (void*) block_ptr_handler);
} finally {
block_handler.CleanupBlock (); block_handler.CleanupBlock ();
} }
} }
}
delegate void nw_listener_advertised_endpoint_changed_handler_t (IntPtr block, IntPtr endpoint, byte added); delegate void nw_listener_advertised_endpoint_changed_handler_t (IntPtr block, IntPtr endpoint, byte added);
static nw_listener_advertised_endpoint_changed_handler_t static_AdvertisedEndpointChangedHandler = TrampolineAdvertisedEndpointChangedHandler; static nw_listener_advertised_endpoint_changed_handler_t static_AdvertisedEndpointChangedHandler = TrampolineAdvertisedEndpointChangedHandler;
@ -204,10 +210,13 @@ namespace Network {
BlockLiteral *block_ptr_handler = &block_handler; BlockLiteral *block_ptr_handler = &block_handler;
block_handler.SetupBlockUnsafe (static_AdvertisedEndpointChangedHandler, callback); block_handler.SetupBlockUnsafe (static_AdvertisedEndpointChangedHandler, callback);
try {
nw_listener_set_advertised_endpoint_changed_handler (GetCheckedHandle (), (void*) block_ptr_handler); nw_listener_set_advertised_endpoint_changed_handler (GetCheckedHandle (), (void*) block_ptr_handler);
} finally {
block_handler.CleanupBlock (); block_handler.CleanupBlock ();
} }
} }
}
[DllImport (Constants.NetworkLibrary)] [DllImport (Constants.NetworkLibrary)]
extern static void nw_listener_set_advertise_descriptor (IntPtr handle, IntPtr advertiseDescriptor); extern static void nw_listener_set_advertise_descriptor (IntPtr handle, IntPtr advertiseDescriptor);

Просмотреть файл

@ -377,10 +377,13 @@ namespace Network {
BlockLiteral *block_ptr_handler = &block_handler; BlockLiteral *block_ptr_handler = &block_handler;
block_handler.SetupBlockUnsafe (static_iterateProhibitedHandler, iterationCallback); block_handler.SetupBlockUnsafe (static_iterateProhibitedHandler, iterationCallback);
try {
nw_parameters_iterate_prohibited_interfaces (GetCheckedHandle (), (void*) block_ptr_handler); nw_parameters_iterate_prohibited_interfaces (GetCheckedHandle (), (void*) block_ptr_handler);
} finally {
block_handler.CleanupBlock (); block_handler.CleanupBlock ();
} }
} }
}
delegate bool nw_parameters_iterate_interface_types_block_t (IntPtr block, NWInterfaceType type); delegate bool nw_parameters_iterate_interface_types_block_t (IntPtr block, NWInterfaceType type);
static nw_parameters_iterate_interface_types_block_t static_IterateProhibitedTypeHandler = TrampolineIterateProhibitedTypeHandler; static nw_parameters_iterate_interface_types_block_t static_IterateProhibitedTypeHandler = TrampolineIterateProhibitedTypeHandler;
@ -408,10 +411,13 @@ namespace Network {
BlockLiteral *block_ptr_handler = &block_handler; BlockLiteral *block_ptr_handler = &block_handler;
block_handler.SetupBlockUnsafe (static_IterateProhibitedTypeHandler, callback); block_handler.SetupBlockUnsafe (static_IterateProhibitedTypeHandler, callback);
try {
nw_parameters_iterate_prohibited_interface_types (GetCheckedHandle (), (void*) block_ptr_handler); nw_parameters_iterate_prohibited_interface_types (GetCheckedHandle (), (void*) block_ptr_handler);
} finally {
block_handler.CleanupBlock (); block_handler.CleanupBlock ();
} }
} }
}
[TV (12,0), Mac (10,14), iOS (12,0)] [TV (12,0), Mac (10,14), iOS (12,0)]
[DllImport (Constants.NetworkLibrary)] [DllImport (Constants.NetworkLibrary)]

Просмотреть файл

@ -121,9 +121,12 @@ namespace Network {
BlockLiteral *block_ptr_handler = &block_handler; BlockLiteral *block_ptr_handler = &block_handler;
block_handler.SetupBlockUnsafe (static_Enumerator, callback); block_handler.SetupBlockUnsafe (static_Enumerator, callback);
try {
nw_path_enumerate_interfaces (GetCheckedHandle (), (void*) block_ptr_handler); nw_path_enumerate_interfaces (GetCheckedHandle (), (void*) block_ptr_handler);
} finally {
block_handler.CleanupBlock (); block_handler.CleanupBlock ();
} }
} }
} }
}
} }

Просмотреть файл

@ -71,10 +71,13 @@ namespace Network {
BlockLiteral *block_ptr_handler = &block_handler; BlockLiteral *block_ptr_handler = &block_handler;
block_handler.SetupBlockUnsafe (static_iterateHandler, callback); block_handler.SetupBlockUnsafe (static_iterateHandler, callback);
try {
nw_protocol_stack_iterate_application_protocols (GetCheckedHandle (), (void*) block_ptr_handler); nw_protocol_stack_iterate_application_protocols (GetCheckedHandle (), (void*) block_ptr_handler);
} finally {
block_handler.CleanupBlock (); block_handler.CleanupBlock ();
} }
} }
}
[TV (12, 0), Mac (10, 14), iOS (12, 0)] [TV (12, 0), Mac (10, 14), iOS (12, 0)]
[DllImport (Constants.NetworkLibrary)] [DllImport (Constants.NetworkLibrary)]