From 3ed796ef9323533b15681df428d91d72a233b416 Mon Sep 17 00:00:00 2001 From: Thomas Kunze Date: Mon, 9 Dec 2019 23:19:13 +0100 Subject: [PATCH] fix more memory bugs --- knx-linux/knx-linux-Debug.vgdbsettings | 2 ++ knx-linux/main.cpp | 2 ++ src/knx/bau_systemB.cpp | 6 ++++++ src/knx/bau_systemB.h | 1 + src/knx/memory.cpp | 13 +++++++------ src/knx/table_object.cpp | 6 ++++++ 6 files changed, 24 insertions(+), 6 deletions(-) diff --git a/knx-linux/knx-linux-Debug.vgdbsettings b/knx-linux/knx-linux-Debug.vgdbsettings index dd1cd88..8e4ab7c 100644 --- a/knx-linux/knx-linux-Debug.vgdbsettings +++ b/knx-linux/knx-linux-Debug.vgdbsettings @@ -36,6 +36,7 @@ false true + true true @@ -110,6 +111,7 @@ True + -DMEDIUM_TYPE=5 true true diff --git a/knx-linux/main.cpp b/knx-linux/main.cpp index 382f11a..a66c347 100644 --- a/knx-linux/main.cpp +++ b/knx-linux/main.cpp @@ -92,6 +92,8 @@ void setup() printf("Aenderung senden: %d\n", knx.paramByte(4)); printf("Abgleich %d\n", knx.paramByte(5)); } + else + println("not configured"); knx.start(); } diff --git a/src/knx/bau_systemB.cpp b/src/knx/bau_systemB.cpp index 0cb2097..595325f 100644 --- a/src/knx/bau_systemB.cpp +++ b/src/knx/bau_systemB.cpp @@ -389,3 +389,9 @@ void BauSystemB::systemNetworkParameterReadIndication(Priority priority, HopCoun break; } } + + +Memory& BauSystemB::memory() +{ + return _memory; +} diff --git a/src/knx/bau_systemB.h b/src/knx/bau_systemB.h index 5ca0ff5..28df70f 100644 --- a/src/knx/bau_systemB.h +++ b/src/knx/bau_systemB.h @@ -21,6 +21,7 @@ class BauSystemB : protected BusAccessUnit DeviceObject& deviceObject(); GroupObjectTableObject& groupObjectTable(); ApplicationProgramObject& parameters(); + Memory& memory(); bool configured(); bool enabled(); void enabled(bool value); diff --git a/src/knx/memory.cpp b/src/knx/memory.cpp index 006a78f..9ca07c5 100644 --- a/src/knx/memory.cpp +++ b/src/knx/memory.cpp @@ -162,7 +162,7 @@ void Memory::freeMemory(uint8_t* ptr) { MemoryBlock* block = _usedList; MemoryBlock* found = nullptr; - while (_usedList) + while (block) { if (block->address == ptr) { @@ -213,15 +213,16 @@ MemoryBlock* Memory::removeFromList(MemoryBlock* head, MemoryBlock* item) } bool found = false; - while (head) + MemoryBlock* block = head; + while (block) { - if (head->next == item) + if (block->next == item) { found = true; - head->next = item->next; + block->next = item->next; break; } - head = head->next; + block = block->next; } if (!found) @@ -374,7 +375,7 @@ void Memory::addNewUsedBlock(uint8_t* address, size_t size) { // we take a middle or end part of the block uint8_t* oldEndAddr = smallerFreeBlock->address + smallerFreeBlock->size; - smallerFreeBlock->size -= (address - smallerFreeBlock->address); + smallerFreeBlock->size = (address - smallerFreeBlock->address); if (address + size < oldEndAddr) { diff --git a/src/knx/table_object.cpp b/src/knx/table_object.cpp index 7fa606a..688a423 100644 --- a/src/knx/table_object.cpp +++ b/src/knx/table_object.cpp @@ -220,6 +220,12 @@ void TableObject::loadEventLoaded(uint8_t* data) break; case LE_UNLOAD: loadState(LS_UNLOADED); + //free nv memory + if (_data) + { + _memory.freeMemory(_data); + _data = 0; + } break; case LE_ADDITIONAL_LOAD_CONTROLS: loadState(LS_ERROR);