Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #17 from jpatton-USGS/crash-fixes
Browse files Browse the repository at this point in the history
Various Crash and Memory Leak fixes
  • Loading branch information
mguy-usgs authored Feb 27, 2018
2 parents d728f79 + 2fa66c8 commit 124a1e3
Show file tree
Hide file tree
Showing 81 changed files with 4,923 additions and 2,462 deletions.
3 changes: 0 additions & 3 deletions config/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ void Config::loadConfigfile() {
configline += currentline;
}

logger::log("debug",
"config::load_configfile: read from configfile: " + configline);

// set the whole config line as our current config
if (setConfigString(configline) == true)
logger::log(
Expand Down
8 changes: 3 additions & 5 deletions doc/GlassConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ An example `glass_init.d` configuration file:
"PickMax": 10000,
"SitePickMax": 30,
"CorrelationMax": 1000,
"Track": false,
"PickDuplicateWindow": 2.5,
"NumNucleationThreads": 5,
"NumHypoThreads": 5,
Expand Down Expand Up @@ -90,16 +89,15 @@ detection performance.
maximum size is reached, glass will start expiring the oldest correlations from
this list as new correlations are received. This value is used for computational
performance tuning.
* **Track** - A mostly depreciated flag controlling whether tracking debug
statements are logged.
* **PickDuplicateWindow** - The time window (+/-) within which to consider a
pick a duplicate of an existing pick from the same station.
* **NumNucleationThreads** - The number of nucleation/detection threads to run
in glass. This value should always be at least one. The upper limit depends
on local machine capabilities.
on local machine capabilities. This value is used for computational performance
tuning.
* **NumHypoThreads** - The number of hypocenter location threads to run in
glass. In general this value should be equal to **NumNucleationThreads** to
avoid race conditions.
avoid race conditions. This value is used for computational performance tuning.
* **WebBackgroundUpdate** - A flag indicating whether to process station updates
to grids on a background thread. If station updates are not processed on a
background thread, glass will halt while the updates are processed.
Expand Down
2 changes: 1 addition & 1 deletion glass-app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.4)

# ----- PROJECT VERSION NUMBER ----- #
set (glass-app_VERSION_MAJOR 0)
set (glass-app_VERSION_MINOR 4)
set (glass-app_VERSION_MINOR 5)
set (glass-app_VERSION_PATCH 0)

# ----- PROJECT ----- #
Expand Down
15 changes: 10 additions & 5 deletions glass-app/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <chrono>
#include <mutex>
#include <string>
#include <memory>

namespace glass {
// Construction/Destruction
Expand Down Expand Up @@ -240,7 +241,9 @@ bool input::setup(json::Object *config) {
"input::setup(): Defaulting to 30 for ShutdownWait");
} else {
m_iShutdownWait = (*config)["ShutdownWait"].ToInt();
logger::log("info", "input::setup(): Using ShutdownWait: "
logger::log(
"info",
"input::setup(): Using ShutdownWait: "
+ std::to_string(m_iShutdownWait));
}

Expand Down Expand Up @@ -304,7 +307,7 @@ void input::clear() {
}

// get next data from input
json::Object* input::getData() {
std::shared_ptr<json::Object> input::getData() {
// just get the value from the queue
return (m_DataQueue->getDataFromQueue());
}
Expand Down Expand Up @@ -444,7 +447,7 @@ bool input::readFiles(std::string extension, const std::string &inputdir,
continue;

// parse the line
json::Object * newdata = parse(extension, line);
std::shared_ptr<json::Object> newdata = parse(extension, line);

// validate the data
if (validate(extension, newdata) == true) {
Expand Down Expand Up @@ -493,7 +496,8 @@ bool input::readFiles(std::string extension, const std::string &inputdir,
}

// parse a json object from an input string
json::Object* input::parse(std::string extension, std::string input) {
std::shared_ptr<json::Object> input::parse(std::string extension,
std::string input) {
// choose the parser based on the extension
// global pick
if (((extension == GPICK_EXTENSION) || (extension == GPICKS_EXTENSION))
Expand All @@ -511,7 +515,8 @@ json::Object* input::parse(std::string extension, std::string input) {
}

// validate a json object
bool input::validate(std::string extension, json::Object* input) {
bool input::validate(std::string extension,
std::shared_ptr<json::Object> input) {
// choose the validator based on the extension
// global pick
if (((extension == GPICK_EXTENSION) || (extension == GPICKS_EXTENSION))
Expand Down
9 changes: 6 additions & 3 deletions glass-app/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <chrono>
#include <mutex>
#include <string>
#include <memory>

#define GPICK_EXTENSION "gpick"
#define GPICKS_EXTENSION "gpicks"
Expand Down Expand Up @@ -111,7 +112,7 @@ class input : public util::iInput, public util::ThreadBaseClass {
*
* \return Returns a pointer to a json::Object containing the data.
*/
json::Object* getData() override;
std::shared_ptr<json::Object> getData() override;

/**
* \brief input data count function
Expand Down Expand Up @@ -261,7 +262,8 @@ class input : public util::iInput, public util::ThreadBaseClass {
* \param extension - A std::string containing the extension to parse
* \return returns a pointer to a json::Object containing the parsed data
*/
virtual json::Object* parse(std::string extension, std::string input);
virtual std::shared_ptr<json::Object> parse(std::string extension,
std::string input);

/**
* \brief validate data function
Expand All @@ -272,7 +274,8 @@ class input : public util::iInput, public util::ThreadBaseClass {
* \param input - A json::Object containing the data to validate
* \return returns true if valid, false otherwise
*/
virtual bool validate(std::string extension, json::Object* input);
virtual bool validate(std::string extension,
std::shared_ptr<json::Object> input);

/**
* \brief cleanup file function
Expand Down
3 changes: 2 additions & 1 deletion glass-app/tests/input_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <fileutil.h>

#include <string>
#include <memory>

#define CONFIGFILENAME "inputtest.d"
#define TESTPATH "testdata"
Expand Down Expand Up @@ -246,7 +247,7 @@ TEST_F(InputTest, Run) {
ASSERT_TRUE(std::ifstream(jsonorigfile).good()) << "jsonorigfile archived";
ASSERT_TRUE(std::ifstream(badfile).good()) << "badfile errored";

json::Object* data = InputThread->getData();
std::shared_ptr<json::Object> data = InputThread->getData();

// assert input data ok
ASSERT_TRUE(data != NULL) << "input data is not null";
Expand Down
59 changes: 35 additions & 24 deletions glass-app/tests/output_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#define OUTPUT3FILE "0BB39FF59826AA4BA63AAA07FFFE713F.jsondetect"
#define RETRACT3FILE "0BB39FF59826AA4BA63AAA07FFFE713F.jsonrtct"

json::Object* GetDataFromFile(std::string filename) {
std::shared_ptr<json::Object> GetDataFromFile(std::string filename) {
std::ifstream infile;
if (std::ifstream(filename).good() != true) {
return (NULL);
Expand All @@ -64,7 +64,8 @@ json::Object* GetDataFromFile(std::string filename) {
// make sure we got valid json
if (deserializedJSON.GetType() != json::ValueType::NULLVal) {
// convert our resulting value to a json object
json::Object *newdata = new json::Object(deserializedJSON.ToObject());
std::shared_ptr<json::Object> newdata = std::make_shared<json::Object>(
json::Object(deserializedJSON.ToObject()));
return (newdata);
}

Expand Down Expand Up @@ -92,7 +93,7 @@ class AssociatorStub : public util::iAssociator {
virtual ~AssociatorStub() {
}

void sendToAssociator(json::Object* message) override {
void sendToAssociator(std::shared_ptr<json::Object> &message) override {
if (message == NULL) {
return;
}
Expand All @@ -110,17 +111,23 @@ class AssociatorStub : public util::iAssociator {
}

if (id == OUTPUTID) {
Output->sendToOutput(GetDataFromFile(hypofile));
std::shared_ptr<json::Object> hypo = GetDataFromFile(hypofile);
Output->sendToOutput(hypo);
} else if (id == OUTPUT2ID) {
if (sentone == false) {
Output->sendToOutput(GetDataFromFile(hypo2file));
std::shared_ptr<json::Object> hypo2 = GetDataFromFile(
hypo2file);
Output->sendToOutput(hypo2);
sentone = true;
} else {
Output->sendToOutput(GetDataFromFile(hypo2updatefile));
std::shared_ptr<json::Object> hypo2Update = GetDataFromFile(
hypo2updatefile);
Output->sendToOutput(hypo2Update);
}

} else if (id == OUTPUT3ID) {
Output->sendToOutput(GetDataFromFile(hypo3file));
std::shared_ptr<json::Object> hypo3 = GetDataFromFile(hypo3file);
Output->sendToOutput(hypo3);
}
}
bool sentone;
Expand Down Expand Up @@ -215,20 +222,24 @@ class OutputTest : public ::testing::Test {

bool configurefail2() {
// configure fail
return (OutputThread->setup(new json::Object(json::Deserialize(CONFIGFAIL1))));
return (OutputThread->setup(
new json::Object(json::Deserialize(CONFIGFAIL1))));
}

bool configurefail3() {
// configure fail
return (OutputThread->setup(new json::Object(json::Deserialize(CONFIGFAIL2))));
return (OutputThread->setup(
new json::Object(json::Deserialize(CONFIGFAIL2))));
}

bool emptyconfig() {
// configure empty
return (OutputThread->setup(new json::Object(json::Deserialize(EMPTYCONFIG))));
return (OutputThread->setup(
new json::Object(json::Deserialize(EMPTYCONFIG))));
}

void CheckData(json::Object * dataone, json::Object * datatwo) {
void CheckData(std::shared_ptr<json::Object> dataone,
std::shared_ptr<json::Object> datatwo) {
if (dataone == NULL) {
return;
}
Expand Down Expand Up @@ -416,7 +427,7 @@ TEST_F(OutputTest, Output) {
// start input thread
OutputThread->start();

json::Object * outputevent = GetDataFromFile(eventfile);
std::shared_ptr<json::Object> outputevent = GetDataFromFile(eventfile);
(*outputevent)["CreateTime"] = glassutil::CDate::encodeISO8601Time(
glassutil::CDate::now());
(*outputevent)["ReportTime"] = glassutil::CDate::encodeISO8601Time(
Expand All @@ -432,8 +443,8 @@ TEST_F(OutputTest, Output) {
ASSERT_TRUE(std::ifstream(outputfile).good()) << "hypo output file created";

// get the data
json::Object * senthypo = GetDataFromFile(hypofile);
json::Object * outputorigin = GetDataFromFile(outputfile);
std::shared_ptr<json::Object> senthypo = GetDataFromFile(hypofile);
std::shared_ptr<json::Object> outputorigin = GetDataFromFile(outputfile);

// check the output data against the input
CheckData(senthypo, outputorigin);
Expand All @@ -446,7 +457,7 @@ TEST_F(OutputTest, Update) {
// start input thread
OutputThread->start();

json::Object * outputevent = GetDataFromFile(event2file);
std::shared_ptr<json::Object> outputevent = GetDataFromFile(event2file);
(*outputevent)["CreateTime"] = glassutil::CDate::encodeISO8601Time(
glassutil::CDate::now());
(*outputevent)["ReportTime"] = glassutil::CDate::encodeISO8601Time(
Expand All @@ -463,16 +474,16 @@ TEST_F(OutputTest, Update) {
<< "hypo output file created";

// get the data
json::Object * senthypo2 = GetDataFromFile(hypo2file);
json::Object * output2origin = GetDataFromFile(output2file);
std::shared_ptr<json::Object> senthypo2 = GetDataFromFile(hypo2file);
std::shared_ptr<json::Object> output2origin = GetDataFromFile(output2file);

// check the output data against the update
CheckData(senthypo2, output2origin);

//remove output for update
std::remove(output2file.c_str());

json::Object * updateevent = GetDataFromFile(event2updatefile);
std::shared_ptr<json::Object> updateevent = GetDataFromFile(event2updatefile);
(*updateevent)["CreateTime"] = glassutil::CDate::encodeISO8601Time(
glassutil::CDate::now());
(*updateevent)["ReportTime"] = glassutil::CDate::encodeISO8601Time(
Expand All @@ -489,8 +500,8 @@ TEST_F(OutputTest, Update) {
<< "hypo update file created";

// get the data
json::Object * sentupdatehypo2 = GetDataFromFile(hypo2updatefile);
json::Object * output2origin2 = GetDataFromFile(output2file);
std::shared_ptr<json::Object> sentupdatehypo2 = GetDataFromFile(hypo2updatefile);
std::shared_ptr<json::Object> output2origin2 = GetDataFromFile(output2file);

// check the output data against the update
CheckData(sentupdatehypo2, output2origin2);
Expand All @@ -503,13 +514,13 @@ TEST_F(OutputTest, Cancel) {
// start input thread
OutputThread->start();

json::Object * outputevent = GetDataFromFile(event3file);
std::shared_ptr<json::Object> outputevent = GetDataFromFile(event3file);
(*outputevent)["CreateTime"] = glassutil::CDate::encodeISO8601Time(
glassutil::CDate::now());
(*outputevent)["ReportTime"] = glassutil::CDate::encodeISO8601Time(
glassutil::CDate::now());

json::Object * cancelmessage = GetDataFromFile(cancel3file);
std::shared_ptr<json::Object> cancelmessage = GetDataFromFile(cancel3file);

// add data to output
OutputThread->sendToOutput(outputevent);
Expand All @@ -534,7 +545,7 @@ TEST_F(OutputTest, Retract) {
// start input thread
OutputThread->start();

json::Object * outputevent = GetDataFromFile(event3file);
std::shared_ptr<json::Object> outputevent = GetDataFromFile(event3file);
(*outputevent)["CreateTime"] = glassutil::CDate::encodeISO8601Time(
glassutil::CDate::now());
(*outputevent)["ReportTime"] = glassutil::CDate::encodeISO8601Time(
Expand All @@ -550,7 +561,7 @@ TEST_F(OutputTest, Retract) {
ASSERT_TRUE(std::ifstream(output3file).good())
<< "output file created";

json::Object * cancelmessage = GetDataFromFile(cancel3file);
std::shared_ptr<json::Object> cancelmessage = GetDataFromFile(cancel3file);

// send cancel to output
OutputThread->sendToOutput(cancelmessage);
Expand Down
2 changes: 1 addition & 1 deletion glass-broker-app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.4)

# ----- PROJECT VERSION NUMBER ----- #
set (glass-broker-app_VERSION_MAJOR 0)
set (glass-broker-app_VERSION_MINOR 4)
set (glass-broker-app_VERSION_MINOR 5)
set (glass-broker-app_VERSION_PATCH 0)

# ----- PROJECT ----- #
Expand Down
4 changes: 2 additions & 2 deletions glass-broker-app/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void input::clear() {
}

// get next data from input
json::Object* input::getData() {
std::shared_ptr<json::Object> input::getData() {
// just get the value from the queue
return (m_DataQueue->getDataFromQueue());
}
Expand All @@ -275,7 +275,7 @@ bool input::work() {

if (message != "") {
logger::log("trace", "input::work(): Got message: " + message);
json::Object* newdata = NULL;
std::shared_ptr<json::Object> newdata;
try {
newdata = m_JSONParser->parse(message);
} catch (const std::exception &e) {
Expand Down
3 changes: 2 additions & 1 deletion glass-broker-app/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <queue>
#include <mutex>
#include <string>
#include <memory>

namespace glass {
/**
Expand Down Expand Up @@ -101,7 +102,7 @@ class input : public util::iInput, public util::ThreadBaseClass {
*
* \return Returns a pointer to a json::Object containing the data.
*/
json::Object* getData() override;
std::shared_ptr<json::Object> getData() override;

/**
* \brief input data count function
Expand Down
2 changes: 1 addition & 1 deletion glasscore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.4)

# ----- PROJECT VERSION NUMBER ----- #
set (glasscore_VERSION_MAJOR 0)
set (glasscore_VERSION_MINOR 4)
set (glasscore_VERSION_MINOR 5)
set (glasscore_VERSION_PATCH 0)

# ----- PROJECT ----- #
Expand Down
Loading

0 comments on commit 124a1e3

Please sign in to comment.