diff options
author | Andrew Tridgell <andrew@tridgell.net> | 2015-02-14 10:22:55 +1100 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2015-02-14 11:16:02 +0100 |
commit | 1b8a830a38caf393cb308ad206d3c23329d58a48 (patch) | |
tree | c95b23d82d05655d579aa5de3982f8334bff7acb /src/drivers/device | |
parent | cbe44e572b0819ff4403baefa1f6595890297b69 (diff) | |
download | px4-firmware-1b8a830a38caf393cb308ad206d3c23329d58a48.tar.gz px4-firmware-1b8a830a38caf393cb308ad206d3c23329d58a48.tar.bz2 px4-firmware-1b8a830a38caf393cb308ad206d3c23329d58a48.zip |
i2c: prevent double free of _dev pointer
this caused heap corruption
Diffstat (limited to 'src/drivers/device')
-rw-r--r-- | src/drivers/device/i2c.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/drivers/device/i2c.cpp b/src/drivers/device/i2c.cpp index 33bb90fc9..092ecd144 100644 --- a/src/drivers/device/i2c.cpp +++ b/src/drivers/device/i2c.cpp @@ -74,8 +74,10 @@ I2C::I2C(const char *name, I2C::~I2C() { - if (_dev) + if (_dev) { up_i2cuninitialize(_dev); + _dev = nullptr; + } } int @@ -118,6 +120,7 @@ I2C::init() // is smaller than the bus frequency if (_bus_clocks[bus_index] > _frequency) { (void)up_i2cuninitialize(_dev); + _dev = nullptr; log("FAIL: too slow for bus #%u: %u KHz, device max: %u KHz)", _bus, _bus_clocks[bus_index] / 1000, _frequency / 1000); ret = -EINVAL; @@ -164,6 +167,7 @@ I2C::init() out: if ((ret != OK) && (_dev != nullptr)) { up_i2cuninitialize(_dev); + _dev = nullptr; } return ret; } |