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:
committed by
Thomas Ingleby
parent
eae4a0cfbf
commit
678e540291
@@ -47,7 +47,7 @@ namespace mraa
|
||||
class MraaIo
|
||||
{
|
||||
private:
|
||||
mraa_io_descriptor* descs;
|
||||
mraa_io_descriptor* descs = nullptr;
|
||||
|
||||
public:
|
||||
MraaIo(const std::string& initStr) : descs()
|
||||
@@ -109,39 +109,40 @@ class MraaIo
|
||||
|
||||
~MraaIo()
|
||||
{
|
||||
if (descs->leftover_str) {
|
||||
free(descs->leftover_str);
|
||||
}
|
||||
|
||||
if (descs->n_aio) {
|
||||
free(descs->aios);
|
||||
}
|
||||
if (descs->n_gpio) {
|
||||
free(descs->gpios);
|
||||
}
|
||||
if (descs->n_i2c) {
|
||||
free(descs->i2cs);
|
||||
}
|
||||
if (descs != nullptr) {
|
||||
if (descs->leftover_str) {
|
||||
free(descs->leftover_str);
|
||||
}
|
||||
if (descs->n_aio) {
|
||||
free(descs->aios);
|
||||
}
|
||||
if (descs->n_gpio) {
|
||||
free(descs->gpios);
|
||||
}
|
||||
if (descs->n_i2c) {
|
||||
free(descs->i2cs);
|
||||
}
|
||||
#if !defined(PERIPHERALMAN)
|
||||
if (descs->n_iio) {
|
||||
free(descs->iios);
|
||||
}
|
||||
if (descs->n_iio) {
|
||||
free(descs->iios);
|
||||
}
|
||||
#endif
|
||||
if (descs->n_pwm) {
|
||||
free(descs->pwms);
|
||||
}
|
||||
if (descs->n_spi) {
|
||||
free(descs->spis);
|
||||
}
|
||||
if (descs->n_uart) {
|
||||
free(descs->uarts);
|
||||
}
|
||||
if (descs->n_uart_ow) {
|
||||
free(descs->uart_ows);
|
||||
}
|
||||
if (descs->n_pwm) {
|
||||
free(descs->pwms);
|
||||
}
|
||||
if (descs->n_spi) {
|
||||
free(descs->spis);
|
||||
}
|
||||
if (descs->n_uart) {
|
||||
free(descs->uarts);
|
||||
}
|
||||
if (descs->n_uart_ow) {
|
||||
free(descs->uart_ows);
|
||||
}
|
||||
|
||||
/* Finally free the mraa_io_descriptor structure. */
|
||||
free(descs);
|
||||
/* Finally free the mraa_io_descriptor structure. */
|
||||
free(descs);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user