diff --git a/targets/AzureRTOS/ST/_nanoCLR/System.Device.I2c/sys_dev_i2c_native_System_Device_I2c_I2cDevice.cpp b/targets/AzureRTOS/ST/_nanoCLR/System.Device.I2c/sys_dev_i2c_native_System_Device_I2c_I2cDevice.cpp index db8d19823b..0cf7fb6ad0 100644 --- a/targets/AzureRTOS/ST/_nanoCLR/System.Device.I2c/sys_dev_i2c_native_System_Device_I2c_I2cDevice.cpp +++ b/targets/AzureRTOS/ST/_nanoCLR/System.Device.I2c/sys_dev_i2c_native_System_Device_I2c_I2cDevice.cpp @@ -580,7 +580,11 @@ HRESULT Library_sys_dev_i2c_native_System_Device_I2c_I2cDevice:: if (status != TX_SUCCESS) { - NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); + // failed to create the thread + // free stack memory + platform_free(palI2c->WorkingThreadStack); + + NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); } // bump custom state diff --git a/targets/AzureRTOS/SiliconLabs/_nanoCLR/System.Device.I2c/sys_dev_i2c_native_System_Device_I2c_I2cDevice.cpp b/targets/AzureRTOS/SiliconLabs/_nanoCLR/System.Device.I2c/sys_dev_i2c_native_System_Device_I2c_I2cDevice.cpp index 564ce25287..b83732fc89 100644 --- a/targets/AzureRTOS/SiliconLabs/_nanoCLR/System.Device.I2c/sys_dev_i2c_native_System_Device_I2c_I2cDevice.cpp +++ b/targets/AzureRTOS/SiliconLabs/_nanoCLR/System.Device.I2c/sys_dev_i2c_native_System_Device_I2c_I2cDevice.cpp @@ -583,7 +583,11 @@ HRESULT Library_sys_dev_i2c_native_System_Device_I2c_I2cDevice:: if (status != TX_SUCCESS) { - NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); + // failed to create the thread + // free stack memory + platform_free(palI2c->WorkingThreadStack); + + NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); } // bump custom state diff --git a/targets/AzureRTOS/SiliconLabs/_nanoCLR/nanoFramework.Device.OneWire/nf_dev_onewire_nanoFramework_Device_OneWire_OneWireHost.cpp b/targets/AzureRTOS/SiliconLabs/_nanoCLR/nanoFramework.Device.OneWire/nf_dev_onewire_nanoFramework_Device_OneWire_OneWireHost.cpp index 5f6a5e0a37..fd79ba0737 100644 --- a/targets/AzureRTOS/SiliconLabs/_nanoCLR/nanoFramework.Device.OneWire/nf_dev_onewire_nanoFramework_Device_OneWire_OneWireHost.cpp +++ b/targets/AzureRTOS/SiliconLabs/_nanoCLR/nanoFramework.Device.OneWire/nf_dev_onewire_nanoFramework_Device_OneWire_OneWireHost.cpp @@ -471,7 +471,11 @@ HRESULT FindOneDevice(CLR_RT_StackFrame &stack, bool findFirst) if (status != TX_SUCCESS) { - NANOCLR_SET_AND_LEAVE(CLR_E_PROCESS_EXCEPTION); + // failed to create the thread + // free stack memory + platform_free(workingThreadStack); + + NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); } // bump custom state