changes
Fork of USBDevice by
Diff: USBMSD/USBMSD.cpp
- Revision:
- 14:d495202c90f4
- Parent:
- 11:eeb3cbbaa996
- Child:
- 18:78bdbce94509
diff -r 16731886c049 -r d495202c90f4 USBMSD/USBMSD.cpp --- a/USBMSD/USBMSD.cpp Tue Sep 10 15:14:55 2013 +0300 +++ b/USBMSD/USBMSD.cpp Thu Sep 12 14:45:27 2013 +0100 @@ -67,8 +67,12 @@ stage = READ_CBW; memset((void *)&cbw, 0, sizeof(CBW)); memset((void *)&csw, 0, sizeof(CSW)); + page = NULL; } +USBMSD::~USBMSD() { + disconnect(); +} // Called in ISR context to process a class specific request @@ -117,6 +121,7 @@ if (BlockCount > 0) { BlockSize = MemorySize / BlockCount; if (BlockSize != 0) { + free(page); page = (uint8_t *)malloc(BlockSize * sizeof(uint8_t)); if (page == NULL) return false; @@ -130,6 +135,12 @@ return true; } +void USBMSD::disconnect() { + //De-allocate MSD page size: + free(page); + page = NULL; + USBDevice::disconnect(); +} void USBMSD::reset() { stage = READ_CBW;