From 08483cf4f751a0560072308c4c59af6559702a1f Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 17 Jan 2018 18:16:45 +0100 Subject: [PATCH] Don't reallocate USB buffers if already allocated USB Configuration was meant to run only once, but if the board comes back from standby the host can reconfigure the device again. Probably a cleaner patch could be free()-ing the buffers on standby() to release the memory but at least we don't leak anymore. Fixes https://github.com/arduino/ArduinoCore-samd/issues/293 --- cores/arduino/USB/USBCore.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cores/arduino/USB/USBCore.cpp b/cores/arduino/USB/USBCore.cpp index fb3046cb4..773d8fccd 100644 --- a/cores/arduino/USB/USBCore.cpp +++ b/cores/arduino/USB/USBCore.cpp @@ -454,7 +454,9 @@ void USBDeviceClass::initEP(uint32_t ep, uint32_t config) } else if (config == (USB_ENDPOINT_TYPE_BULK | USB_ENDPOINT_OUT(0))) { - epHandlers[ep] = new DoubleBufferedEPOutHandler(usbd, ep, 256); + if (epHandlers[ep] == NULL) { + epHandlers[ep] = new DoubleBufferedEPOutHandler(usbd, ep, 256); + } } else if (config == (USB_ENDPOINT_TYPE_BULK | USB_ENDPOINT_IN(0))) {