fixed memory leaks, added cleanup code, added valgrind scripts to test binaries

This commit is contained in:
Martin Preuss
2023-08-09 17:24:44 +02:00
parent 4701a71986
commit b5916acf79
41 changed files with 991 additions and 170 deletions

View File

@@ -48,7 +48,7 @@
<default>0</default>
<preset>0</preset>
<access>public</access>
<flags>with_getbymember</flags>
<flags>own with_getbymember</flags>
</member>
<member name="mqttDataType" type="int" maxlen="8">

View File

@@ -41,14 +41,14 @@
<default>0</default>
<preset>0</preset>
<access>public</access>
<flags>with_getbymember</flags>
<flags>own with_getbymember</flags>
</member>
<member name="description" type="char_ptr" maxlen="256">
<default>0</default>
<preset>0</preset>
<access>public</access>
<flags></flags>
<flags>own</flags>
</member>
<member name="colour" type="uint32_t" maxlen="8">

View File

@@ -204,6 +204,37 @@ AQH_VALUE *AQH_Storage_GetValueById(const AQH_STORAGE *sto, uint64_t id)
uint32_t AQH_Storage_GetRuntimeFlags(const AQH_STORAGE *sto)
{
return sto?sto->runtimeFlags:0;
}
void AQH_Storage_SetRuntimeFlags(AQH_STORAGE *sto, uint32_t flags)
{
if (sto)
sto->runtimeFlags=flags;
}
void AQH_Storage_AddRuntimeFlags(AQH_STORAGE *sto, uint32_t flags)
{
if (sto)
sto->runtimeFlags|=flags;
}
void AQH_Storage_SubRuntimeFlags(AQH_STORAGE *sto, uint32_t flags)
{
if (sto)
sto->runtimeFlags&=~flags;
}
void AQH_Storage_HandleMqttPublish(AQH_STORAGE *sto, const char *topic, const char *value)
{
/* TODO */
@@ -216,7 +247,10 @@ int AQH_Storage_Init(AQH_STORAGE *sto)
int rv;
rv=GWEN_Directory_GetPath(sto->stateFile,
GWEN_PATH_FLAGS_CHECKROOT | GWEN_PATH_FLAGS_PATHMUSTEXIST | GWEN_PATH_FLAGS_NAMEMUSTEXIST);
GWEN_PATH_FLAGS_CHECKROOT |
GWEN_PATH_FLAGS_PATHMUSTEXIST |
GWEN_PATH_FLAGS_NAMEMUSTEXIST |
GWEN_PATH_FLAGS_VARIABLE);
if (rv==0) {
rv=AQH_Storage_ReadStateFile(sto, sto->stateFile);
if (rv<0) {
@@ -225,7 +259,7 @@ int AQH_Storage_Init(AQH_STORAGE *sto)
}
}
else {
DBG_WARN(AQH_LOGDOMAIN, "State file \"%s\" not available, will try to create it later", sto->stateFile);
DBG_WARN(AQH_LOGDOMAIN, "State file \"%s\" not available, will try to create it later (%d)", sto->stateFile, rv);
}
return 0;
@@ -242,7 +276,7 @@ int AQH_Storage_WriteState(AQH_STORAGE *sto)
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
return rv;
}
sto->runtimeFlags&=~AQH_STORAGE_RTFLAGS_MODIFIED;
return 0;
}

View File

@@ -34,6 +34,9 @@ typedef struct AQH_STORAGE AQH_STORAGE;
#include "aqhome/data/datapoint.h"
#define AQH_STORAGE_RTFLAGS_MODIFIED 0x0001
#ifdef __cplusplus
extern "C" {
@@ -67,6 +70,11 @@ AQHOME_API AQH_VALUE *AQH_Storage_GetValueById(const AQH_STORAGE *sto, uint64_t
AQHOME_API const char *AQH_Storage_GetStateFile(const AQH_STORAGE *sto);
AQHOME_API void AQH_Storage_SetStateFile(AQH_STORAGE *sto, const char *s);
AQHOME_API uint32_t AQH_Storage_GetRuntimeFlags(const AQH_STORAGE *sto);
AQHOME_API void AQH_Storage_SetRuntimeFlags(AQH_STORAGE *sto, uint32_t flags);
AQHOME_API void AQH_Storage_AddRuntimeFlags(AQH_STORAGE *sto, uint32_t flags);
AQHOME_API void AQH_Storage_SubRuntimeFlags(AQH_STORAGE *sto, uint32_t flags);
AQHOME_API int AQH_Storage_Init(AQH_STORAGE *sto);
AQHOME_API int AQH_Storage_WriteState(AQH_STORAGE *sto);

View File

@@ -41,6 +41,8 @@ struct AQH_STORAGE {
uint64_t lastValueId;
char *stateFile;
uint32_t runtimeFlags;
};

View File

@@ -57,6 +57,8 @@ int AQH_Storage_ReadStateFile(AQH_STORAGE *sto, const char *sFilename)
_readTopicsFromXml(sto, rootNode);
_readValuesFromXml(sto, rootNode);
GWEN_XMLNode_free(rootNode);
return 0;
}

View File

@@ -125,7 +125,7 @@ void _writeDevicesToXml(const AQH_STORAGE *sto, GWEN_XMLNODE *rootNode)
nElems=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, AQH_STORAGE_XML_ELEMENTNAME_DEVICES);
elem=AQH_Device_List_First(sto->roomList);
elem=AQH_Device_List_First(sto->deviceList);
while(elem) {
GWEN_XMLNODE *nElem;

View File

@@ -55,14 +55,14 @@
<default>0</default>
<preset>0</preset>
<access>public</access>
<flags></flags>
<flags>own</flags>
</member>
<member name="dataPath" type="char_ptr" maxlen="256">
<default>0</default>
<preset>0</preset>
<access>public</access>
<flags></flags>
<flags>own</flags>
</member>