From ad1d72df6fc140999c3ca31e6b138fd7d1498728 Mon Sep 17 00:00:00 2001 From: Niklas Hauser <121870655+niklaut@users.noreply.github.com> Date: Thu, 7 Sep 2023 20:22:58 +0200 Subject: [PATCH] uORB: fix hardfault in uORB calloc implementation When running out-of-memory, the malloc returns NULL and the memset then tries to write to address 0 which results in a hardfault. --- platforms/common/uORB/uORBDeviceNode.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/platforms/common/uORB/uORBDeviceNode.cpp b/platforms/common/uORB/uORBDeviceNode.cpp index 7cc5c9bd3e..112170de6b 100644 --- a/platforms/common/uORB/uORBDeviceNode.cpp +++ b/platforms/common/uORB/uORBDeviceNode.cpp @@ -188,7 +188,10 @@ uORB::DeviceNode::write(cdev::file_t *filp, const char *buffer, size_t buflen) if (nullptr == _data) { const size_t data_size = _meta->o_size * _queue_size; _data = (uint8_t *) px4_cache_aligned_alloc(data_size); - memset(_data, 0, data_size); + + if (_data) { + memset(_data, 0, data_size); + } } unlock();