fix more memory bugs

This commit is contained in:
Thomas Kunze 2019-12-09 23:19:13 +01:00
parent 77a0d6fc2e
commit 3ed796ef93
6 changed files with 24 additions and 6 deletions

View File

@ -36,6 +36,7 @@
</FileMasks> </FileMasks>
<TransferNewFilesOnly>false</TransferNewFilesOnly> <TransferNewFilesOnly>false</TransferNewFilesOnly>
<IncludeSubdirectories>true</IncludeSubdirectories> <IncludeSubdirectories>true</IncludeSubdirectories>
<SelectedDirectories />
<DeleteDisappearedFiles>true</DeleteDisappearedFiles> <DeleteDisappearedFiles>true</DeleteDisappearedFiles>
<ApplyGlobalExclusionList>true</ApplyGlobalExclusionList> <ApplyGlobalExclusionList>true</ApplyGlobalExclusionList>
<Extension> <Extension>
@ -110,6 +111,7 @@
<ImportedPropertySheets /> <ImportedPropertySheets />
<CodeSense> <CodeSense>
<Enabled>True</Enabled> <Enabled>True</Enabled>
<CXXFLAGS>-DMEDIUM_TYPE=5</CXXFLAGS>
<ExtraSettings> <ExtraSettings>
<HideErrorsInSystemHeaders>true</HideErrorsInSystemHeaders> <HideErrorsInSystemHeaders>true</HideErrorsInSystemHeaders>
<SupportLightweightReferenceAnalysis>true</SupportLightweightReferenceAnalysis> <SupportLightweightReferenceAnalysis>true</SupportLightweightReferenceAnalysis>

View File

@ -92,6 +92,8 @@ void setup()
printf("Aenderung senden: %d\n", knx.paramByte(4)); printf("Aenderung senden: %d\n", knx.paramByte(4));
printf("Abgleich %d\n", knx.paramByte(5)); printf("Abgleich %d\n", knx.paramByte(5));
} }
else
println("not configured");
knx.start(); knx.start();
} }

View File

@ -389,3 +389,9 @@ void BauSystemB::systemNetworkParameterReadIndication(Priority priority, HopCoun
break; break;
} }
} }
Memory& BauSystemB::memory()
{
return _memory;
}

View File

@ -21,6 +21,7 @@ class BauSystemB : protected BusAccessUnit
DeviceObject& deviceObject(); DeviceObject& deviceObject();
GroupObjectTableObject& groupObjectTable(); GroupObjectTableObject& groupObjectTable();
ApplicationProgramObject& parameters(); ApplicationProgramObject& parameters();
Memory& memory();
bool configured(); bool configured();
bool enabled(); bool enabled();
void enabled(bool value); void enabled(bool value);

View File

@ -162,7 +162,7 @@ void Memory::freeMemory(uint8_t* ptr)
{ {
MemoryBlock* block = _usedList; MemoryBlock* block = _usedList;
MemoryBlock* found = nullptr; MemoryBlock* found = nullptr;
while (_usedList) while (block)
{ {
if (block->address == ptr) if (block->address == ptr)
{ {
@ -213,15 +213,16 @@ MemoryBlock* Memory::removeFromList(MemoryBlock* head, MemoryBlock* item)
} }
bool found = false; bool found = false;
while (head) MemoryBlock* block = head;
while (block)
{ {
if (head->next == item) if (block->next == item)
{ {
found = true; found = true;
head->next = item->next; block->next = item->next;
break; break;
} }
head = head->next; block = block->next;
} }
if (!found) 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 // we take a middle or end part of the block
uint8_t* oldEndAddr = smallerFreeBlock->address + smallerFreeBlock->size; uint8_t* oldEndAddr = smallerFreeBlock->address + smallerFreeBlock->size;
smallerFreeBlock->size -= (address - smallerFreeBlock->address); smallerFreeBlock->size = (address - smallerFreeBlock->address);
if (address + size < oldEndAddr) if (address + size < oldEndAddr)
{ {

View File

@ -220,6 +220,12 @@ void TableObject::loadEventLoaded(uint8_t* data)
break; break;
case LE_UNLOAD: case LE_UNLOAD:
loadState(LS_UNLOADED); loadState(LS_UNLOADED);
//free nv memory
if (_data)
{
_memory.freeMemory(_data);
_data = 0;
}
break; break;
case LE_ADDITIONAL_LOAD_CONTROLS: case LE_ADDITIONAL_LOAD_CONTROLS:
loadState(LS_ERROR); loadState(LS_ERROR);