From 8cb180d081ccd2991ff7b9c35ec318945a887031 Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Wed, 9 Oct 2024 09:38:39 +0200 Subject: [PATCH] Fix #74, memory leak in verifyBlock() (#75) - Fix #74, memory leak in setBlockVerify() --- CHANGELOG.md | 6 +++++- I2C_eeprom.cpp | 8 ++++++-- I2C_eeprom.h | 4 ++-- README.md | 9 +++++---- library.json | 2 +- library.properties | 2 +- 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a44ea25..85b7719 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.9.0] - 2024-10-09 +- Fix #74, memory leak in setBlockVerify() - kudos to cmichailidis + +---- + ## [1.8.5] - 2024-04-22 - Fix #72, force requestFrom parameters to use int type - ## [1.8.4] - 2024-04-20 - Fix #70, increase length internal buffer. - add compile time flag **EN_AUTO_WRITE_PROTECT** (thanks to microfoundry) diff --git a/I2C_eeprom.cpp b/I2C_eeprom.cpp index fba5dd1..df1e261 100644 --- a/I2C_eeprom.cpp +++ b/I2C_eeprom.cpp @@ -1,7 +1,7 @@ // // FILE: I2C_eeprom.cpp // AUTHOR: Rob Tillaart -// VERSION: 1.8.5 +// VERSION: 1.9.0 // PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al. // URL: https://github.com/RobTillaart/I2C_EEPROM @@ -235,7 +235,11 @@ bool I2C_eeprom::setBlockVerify(const uint16_t memoryAddress, const uint8_t valu if (setBlock(memoryAddress, value, length) != 0) return false; uint8_t * data = (uint8_t *) malloc(length); if (data == NULL) return false; - if (readBlock(memoryAddress, data, length) != length) return false; + if (readBlock(memoryAddress, data, length) != length) + { + free(data); + return false; + } for (uint16_t i = 0; i < length; i++) { if (data[i] != value) diff --git a/I2C_eeprom.h b/I2C_eeprom.h index 48009bf..f39a062 100644 --- a/I2C_eeprom.h +++ b/I2C_eeprom.h @@ -2,7 +2,7 @@ // // FILE: I2C_eeprom.h // AUTHOR: Rob Tillaart -// VERSION: 1.8.5 +// VERSION: 1.9.0 // PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al. // URL: https://github.com/RobTillaart/I2C_EEPROM @@ -11,7 +11,7 @@ #include "Wire.h" -#define I2C_EEPROM_VERSION (F("1.8.5")) +#define I2C_EEPROM_VERSION (F("1.9.0")) #define I2C_DEVICESIZE_24LC512 65536 #define I2C_DEVICESIZE_24LC256 32768 diff --git a/README.md b/README.md index e60892a..0198e79 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Not supported is the identification page functions. The **I2C_eeprom_cyclic_store** interface is documented [here](README_cyclic_store.md) -#### RP2040 +### RP2040 There are at least two boards modules for the RP2040 that use a different Wire libraries. One from "Earle F. Philhower" and an "MBED" one. See issues #53 and #55 for details. @@ -36,7 +36,9 @@ to solve the issue #53 while being backwards compatible. If a better solution is found, it will be implemented. -#### Breaking change +### Breaking change + +Version 1.9.0 fixed a memory leak in **verifyBlock()**. Version 1.8.0 introduced a breaking change. You cannot set the pins in **begin()** any more. @@ -45,7 +47,7 @@ The user has to call **Wire.begin()** and can optionally set the Wire pins before calling **I2C_eeprom.begin()**. -#### Links +### Related - https://github.com/RobTillaart/I2C_24LC1025 @@ -137,7 +139,6 @@ Same as write and update functions above. Returns true if successful, false indi Returns true is buffer equals memoryAddres for length bytes. - ### Other - **uint32_t getDeviceSize()** idem diff --git a/library.json b/library.json index f567d7b..8d0857c 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/I2C_EEPROM.git" }, - "version": "1.8.5", + "version": "1.9.0", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/library.properties b/library.properties index 5aa984f..54b4579 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=I2C_EEPROM -version=1.8.5 +version=1.9.0 author=Rob Tillaart maintainer=Rob Tillaart sentence=Library for I2C EEPROMS