From 29352c8730b0ad237d50cd371efa4227dad569b3 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 19 Dec 2022 09:28:46 +0100 Subject: [PATCH] SPI: fix crash on end() called before begin() Fixes https://github.com/arduino/ArduinoCore-mbed/issues/590 --- libraries/SPI/SPI.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/SPI/SPI.cpp b/libraries/SPI/SPI.cpp index b2b970ee5..6cc61a747 100644 --- a/libraries/SPI/SPI.cpp +++ b/libraries/SPI/SPI.cpp @@ -106,8 +106,10 @@ void arduino::MbedSPI::begin() { } void arduino::MbedSPI::end() { - if (dev->obj != NULL) { + if (dev != NULL && dev->obj != NULL) { delete dev->obj; + delete dev; + dev = NULL; } }