Skip to content

Commit 2bb5406

Browse files
facchinmsandeepmistry
authored andcommitted
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 #293
1 parent 395695b commit 2bb5406

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

cores/arduino/USB/USBCore.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,9 @@ void USBDeviceClass::initEP(uint32_t ep, uint32_t config)
454454
}
455455
else if (config == (USB_ENDPOINT_TYPE_BULK | USB_ENDPOINT_OUT(0)))
456456
{
457-
epHandlers[ep] = new DoubleBufferedEPOutHandler(usbd, ep, 256);
457+
if (epHandlers[ep] == NULL) {
458+
epHandlers[ep] = new DoubleBufferedEPOutHandler(usbd, ep, 256);
459+
}
458460
}
459461
else if (config == (USB_ENDPOINT_TYPE_BULK | USB_ENDPOINT_IN(0)))
460462
{

0 commit comments

Comments
 (0)