fixed some memory issues
This commit is contained in:
+26
-14
@@ -90,8 +90,11 @@ static struct options opt = {
|
|||||||
100 // dumpSize
|
100 // dumpSize
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** the @a MessageMap instance, or NULL. */
|
||||||
|
static MessageMap* s_messageMap = NULL;
|
||||||
|
|
||||||
/** the @a MainLoop instance, or NULL. */
|
/** the @a MainLoop instance, or NULL. */
|
||||||
static MainLoop* mainLoop = NULL;
|
static MainLoop* s_mainLoop = NULL;
|
||||||
|
|
||||||
/** the version string of the program. */
|
/** the version string of the program. */
|
||||||
const char *argp_program_version = ""PACKAGE_STRING"";
|
const char *argp_program_version = ""PACKAGE_STRING"";
|
||||||
@@ -442,12 +445,15 @@ void closePidFile()
|
|||||||
void shutdown()
|
void shutdown()
|
||||||
{
|
{
|
||||||
// stop main loop and all dependent components
|
// stop main loop and all dependent components
|
||||||
if (mainLoop != NULL) {
|
if (s_mainLoop != NULL) {
|
||||||
delete mainLoop;
|
delete s_mainLoop;
|
||||||
mainLoop = NULL;
|
s_mainLoop = NULL;
|
||||||
|
}
|
||||||
|
if (s_messageMap!=NULL) {
|
||||||
|
delete s_messageMap;
|
||||||
|
s_messageMap = NULL;
|
||||||
}
|
}
|
||||||
// free templates
|
// free templates
|
||||||
globalTemplates.clear(); // TODO should be unnecessary due to dtor
|
|
||||||
for (map<string, DataFieldTemplates*>::iterator it = templatesByPath.begin(); it != templatesByPath.end(); it++) {
|
for (map<string, DataFieldTemplates*>::iterator it = templatesByPath.begin(); it != templatesByPath.end(); it++) {
|
||||||
delete it->second;
|
delete it->second;
|
||||||
}
|
}
|
||||||
@@ -580,6 +586,11 @@ result_t loadConfigFiles(MessageMap* messages, bool verbose)
|
|||||||
string path = string(opt.configPath);
|
string path = string(opt.configPath);
|
||||||
messages->clear();
|
messages->clear();
|
||||||
globalTemplates.clear();
|
globalTemplates.clear();
|
||||||
|
for (map<string, DataFieldTemplates*>::iterator it = templatesByPath.begin(); it != templatesByPath.end(); it++) {
|
||||||
|
delete it->second;
|
||||||
|
it->second = NULL;
|
||||||
|
}
|
||||||
|
templatesByPath.clear();
|
||||||
result_t result = globalTemplates.readFromFile(path+"/_templates.csv", NULL, verbose);
|
result_t result = globalTemplates.readFromFile(path+"/_templates.csv", NULL, verbose);
|
||||||
if (result == RESULT_OK)
|
if (result == RESULT_OK)
|
||||||
logInfo(lf_main, "read templates");
|
logInfo(lf_main, "read templates");
|
||||||
@@ -797,17 +808,18 @@ int main(int argc, char* argv[])
|
|||||||
if (argp_parse(&argp, argc, argv, ARGP_IN_ORDER, NULL, &opt) != 0)
|
if (argp_parse(&argp, argc, argv, ARGP_IN_ORDER, NULL, &opt) != 0)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
MessageMap messages = MessageMap(opt.checkConfig && opt.scanConfig);
|
s_messageMap = new MessageMap(opt.checkConfig && opt.scanConfig);
|
||||||
if (opt.checkConfig) {
|
if (opt.checkConfig) {
|
||||||
logNotice(lf_main, "Performing configuration check...");
|
logNotice(lf_main, "Performing configuration check...");
|
||||||
|
|
||||||
result_t result = loadConfigFiles(&messages, true);
|
result_t result = loadConfigFiles(s_messageMap, true);
|
||||||
|
|
||||||
if (result == RESULT_OK && opt.checkConfig > 1) {
|
if (result == RESULT_OK && opt.checkConfig > 1) {
|
||||||
logNotice(lf_main, "Configuration dump:");
|
logNotice(lf_main, "Configuration dump:");
|
||||||
messages.dump(cout);
|
s_messageMap->dump(cout);
|
||||||
}
|
}
|
||||||
messages.clear();
|
delete s_messageMap;
|
||||||
|
s_messageMap = NULL;
|
||||||
globalTemplates.clear();
|
globalTemplates.clear();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -833,14 +845,14 @@ int main(int argc, char* argv[])
|
|||||||
logNotice(lf_main, PACKAGE_STRING " started");
|
logNotice(lf_main, PACKAGE_STRING " started");
|
||||||
|
|
||||||
// load configuration files
|
// load configuration files
|
||||||
loadConfigFiles(&messages);
|
loadConfigFiles(s_messageMap);
|
||||||
if (messages.sizeConditions()>0 && opt.pollInterval==0)
|
if (s_messageMap->sizeConditions()>0 && opt.pollInterval==0)
|
||||||
logError(lf_main, "conditions require a poll interval > 0");
|
logError(lf_main, "conditions require a poll interval > 0");
|
||||||
|
|
||||||
// create the MainLoop and run it
|
// create the MainLoop and run it
|
||||||
mainLoop = new MainLoop(opt, device, &messages);
|
s_mainLoop = new MainLoop(opt, device, s_messageMap);
|
||||||
mainLoop->start("mainloop");
|
s_mainLoop->start("mainloop");
|
||||||
mainLoop->join();
|
s_mainLoop->join();
|
||||||
|
|
||||||
// shutdown
|
// shutdown
|
||||||
shutdown();
|
shutdown();
|
||||||
|
|||||||
+1
-1
@@ -51,7 +51,7 @@ struct options
|
|||||||
uint16_t port; //!< port to listen for command line connections [8888]
|
uint16_t port; //!< port to listen for command line connections [8888]
|
||||||
bool localOnly; //!< listen on 127.0.0.1 interface only
|
bool localOnly; //!< listen on 127.0.0.1 interface only
|
||||||
uint16_t httpPort; //!< optional port to listen for HTTP connections, 0 to disable [0]
|
uint16_t httpPort; //!< optional port to listen for HTTP connections, 0 to disable [0]
|
||||||
string htmlPath; //!< path for HTML files served by the HTTP port [/var/ebusd/html]
|
const char* htmlPath; //!< path for HTML files served by the HTTP port [/var/ebusd/html]
|
||||||
|
|
||||||
const char* logFile; //!< log file name [/var/log/ebusd.log]
|
const char* logFile; //!< log file name [/var/log/ebusd.log]
|
||||||
bool logRaw; //!< log each received/sent byte on the bus
|
bool logRaw; //!< log each received/sent byte on the bus
|
||||||
|
|||||||
@@ -87,8 +87,6 @@ MainLoop::~MainLoop()
|
|||||||
delete m_device;
|
delete m_device;
|
||||||
m_device = NULL;
|
m_device = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_messages->clear(); // TODO should be unnecessary
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainLoop::run()
|
void MainLoop::run()
|
||||||
|
|||||||
@@ -184,6 +184,8 @@ Network::~Network()
|
|||||||
|
|
||||||
if (m_tcpServer != NULL)
|
if (m_tcpServer != NULL)
|
||||||
delete m_tcpServer;
|
delete m_tcpServer;
|
||||||
|
if (m_httpServer != NULL)
|
||||||
|
delete m_httpServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Network::run()
|
void Network::run()
|
||||||
|
|||||||
Reference in New Issue
Block a user