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