fixed memory leaks, added cleanup code, added valgrind scripts to test binaries
This commit is contained in:
@@ -13,7 +13,9 @@
|
||||
|
||||
#include "./loop.h"
|
||||
#include "./loop_http.h"
|
||||
#include "./aqhomehttp.h"
|
||||
#include "./aqhomestorage_p.h"
|
||||
#include "aqhome/http/httpservice_conf.h"
|
||||
|
||||
#include <gwenhywfar/gwenhywfar.h>
|
||||
#include <gwenhywfar/args.h>
|
||||
@@ -34,6 +36,7 @@
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static int _writeModifiedSessions(AQHOME_STORAGE *aqh);
|
||||
|
||||
|
||||
|
||||
@@ -48,9 +51,97 @@ void AqHomeStorage_Loop(AQHOME_STORAGE *aqh, int timeoutInMsecs)
|
||||
GWEN_MsgEndpoint_ChildrenIoLoop(aqh->rootEndpoint, timeoutInMsecs);
|
||||
AqHomeStorage_ReadAndHandleHttpMessages(aqh);
|
||||
// AqHomeStorage_ReadAndHandleIpcMessages(aqh);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AqHomeStorage_WriteStorageIfChanged(AQHOME_STORAGE *aqh)
|
||||
{
|
||||
if (AQH_Storage_GetRuntimeFlags(aqh->storage) & AQH_STORAGE_RTFLAGS_MODIFIED) {
|
||||
int rv;
|
||||
|
||||
DBG_INFO(NULL, "Storage modified, writing statefile");
|
||||
rv=AqHomeHttpService_LockStorage(aqh->httpService);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "Error locking storage (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
rv=AQH_Storage_WriteState(aqh->storage);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "Error writing state file (%d)", rv);
|
||||
AqHomeHttpService_UnlockStorage(aqh->httpService);
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv=AqHomeHttpService_UnlockStorage(aqh->httpService);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "Error unlocking storage (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AqHomeStorage_WriteServiceIfChanged(AQHOME_STORAGE *aqh)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv=_writeModifiedSessions(aqh);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _writeModifiedSessions(AQHOME_STORAGE *aqh)
|
||||
{
|
||||
AQH_SESSION_LIST *sessionList;
|
||||
int rv;
|
||||
|
||||
rv=AQH_HttpService_LockSessions(aqh->httpService);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "Error locking sessions (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
sessionList=AQH_Service_GetSessionList(aqh->httpService);
|
||||
if (sessionList) {
|
||||
AQH_SESSION *session;
|
||||
|
||||
session=AQH_Session_List_First(sessionList);
|
||||
while(session) {
|
||||
if (AQH_Session_GetRuntimeFlags(session) & AQH_SESSION_RTFLAGS_MODIFIED) {
|
||||
DBG_INFO(NULL, "Session \"%s\" modified, writing", AQH_Session_GetUid(session));
|
||||
rv=AQH_HttpService_SaveSession(aqh->httpService, session);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "Error writing session \"%s\" (%d)", AQH_Session_GetUid(session), rv);
|
||||
}
|
||||
else {
|
||||
DBG_DEBUG(NULL, "Session \"%s\" written", AQH_Session_GetUid(session));
|
||||
AQH_Session_SubRuntimeFlags(session, AQH_SESSION_RTFLAGS_MODIFIED);
|
||||
}
|
||||
}
|
||||
session=AQH_Session_List_Next(session);
|
||||
}
|
||||
}
|
||||
|
||||
rv=AQH_HttpService_UnlockSessions(aqh->httpService);
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "Error unlocking sessions (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user