Private
Public Access
2
0

initio: Add safety checks inside MraaIo destructor

Signed-off-by: Adelin Dobre <adelin.dobre@rinftech.com>
Signed-off-by: Thomas Ingleby <thomas.ingleby@intel.com>
This commit is contained in:
Adelin Dobre
2018-12-21 13:51:03 +02:00
committed by Thomas Ingleby
parent eae4a0cfbf
commit 678e540291

View File

@@ -47,7 +47,7 @@ namespace mraa
class MraaIo class MraaIo
{ {
private: private:
mraa_io_descriptor* descs; mraa_io_descriptor* descs = nullptr;
public: public:
MraaIo(const std::string& initStr) : descs() MraaIo(const std::string& initStr) : descs()
@@ -109,39 +109,40 @@ class MraaIo
~MraaIo() ~MraaIo()
{ {
if (descs->leftover_str) { if (descs != nullptr) {
free(descs->leftover_str); if (descs->leftover_str) {
} free(descs->leftover_str);
}
if (descs->n_aio) { if (descs->n_aio) {
free(descs->aios); free(descs->aios);
} }
if (descs->n_gpio) { if (descs->n_gpio) {
free(descs->gpios); free(descs->gpios);
} }
if (descs->n_i2c) { if (descs->n_i2c) {
free(descs->i2cs); free(descs->i2cs);
} }
#if !defined(PERIPHERALMAN) #if !defined(PERIPHERALMAN)
if (descs->n_iio) { if (descs->n_iio) {
free(descs->iios); free(descs->iios);
} }
#endif #endif
if (descs->n_pwm) { if (descs->n_pwm) {
free(descs->pwms); free(descs->pwms);
} }
if (descs->n_spi) { if (descs->n_spi) {
free(descs->spis); free(descs->spis);
} }
if (descs->n_uart) { if (descs->n_uart) {
free(descs->uarts); free(descs->uarts);
} }
if (descs->n_uart_ow) { if (descs->n_uart_ow) {
free(descs->uart_ows); free(descs->uart_ows);
} }
/* Finally free the mraa_io_descriptor structure. */ /* Finally free the mraa_io_descriptor structure. */
free(descs); free(descs);
}
} }
public: public: