Skip to content
Permalink
Browse files

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>
  • Loading branch information...
adelindobre authored and tingleby committed Dec 21, 2018
1 parent eae4a0c commit 678e5402915fdaa488dc4ab455dd0193d64d8bdb
Showing with 32 additions and 31 deletions.
  1. +32 −31 api/mraa/initio.hpp
@@ -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_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);
}
if (descs->n_uart_ow) {
free(descs->uart_ows);
}

/* Finally free the mraa_io_descriptor structure. */
free(descs);
}

public:

0 comments on commit 678e540

Please sign in to comment.
You can’t perform that action at this time.