Merge pull request #40 from jgfoster/memory_leak

Release memory allocated in constructor to avoid memory leak
This commit is contained in:
Limor "Ladyada" Fried 2020-11-30 19:07:32 -05:00 committed by GitHub
commit a8c9c5183c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -70,6 +70,16 @@ Adafruit_SPIDevice::Adafruit_SPIDevice(int8_t cspin, int8_t sckpin,
_spi = NULL;
}
/*!
* @brief Release memory allocated in constructors
*/
Adafruit_SPIDevice::~Adafruit_SPIDevice() {
if (_spiSetting) {
delete _spiSetting;
_spiSetting = nullptr;
}
}
/*!
* @brief Initializes SPI bus and sets CS pin high
* @return Always returns true because there's no way to test success of SPI

View File

@ -66,6 +66,7 @@ public:
uint32_t freq = 1000000,
BitOrder dataOrder = SPI_BITORDER_MSBFIRST,
uint8_t dataMode = SPI_MODE0);
~Adafruit_SPIDevice();
bool begin(void);
bool read(uint8_t *buffer, size_t len, uint8_t sendvalue = 0xFF);