Skip to content

Commit

Permalink
Exchanged a crash in destructor for a memory leak. #45 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed Jul 17, 2017
1 parent 8b1ddd1 commit 75d0573
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion include/CCDB/Calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class Calibration {
* @parameter [in] namepath - full namepath is /path/to/data:run:variation:time but usually it is only /path/to/data
* @return DAssignment *
*/
virtual std::shared_ptr<Assignment> GetAssignment(const string& namepath, bool loadColumns = true);
virtual Assignment* GetAssignment(const string& namepath, bool loadColumns = true);

/** @brief if true the data will be cached
*
Expand Down
18 changes: 9 additions & 9 deletions src/Library/Calibration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bool Calibration::GetCalib( vector< map<string, string> > &values, const string

auto assignment = GetAssignment(namepath, true);

if(!assignment.get())
if(!assignment)
{
return false; //TODO possibly exception throwing?
}
Expand Down Expand Up @@ -218,7 +218,7 @@ bool Calibration::GetCalib( vector< vector<string> > &values, const string & nam

auto assignment = GetAssignment(namepath, false);

if(!assignment.get())
if(!assignment)
{
return false;
}
Expand Down Expand Up @@ -315,7 +315,7 @@ bool Calibration::GetCalib( map<string, string> &values, const string & namepath

auto assignment = GetAssignment(namepath, true);

if(assignment.get() == NULL)
if(assignment == NULL)
{
//TODO possibly exception throwing?
return false;
Expand Down Expand Up @@ -453,7 +453,7 @@ bool Calibration::GetCalib( vector<string> &values, const string & namepath )

auto assignment = GetAssignment(namepath, true);

if(assignment.get() == NULL) return false; //TODO possibly exception throwing?
if(assignment == NULL) return false; //TODO possibly exception throwing?

//Get data
values.clear();
Expand Down Expand Up @@ -582,7 +582,7 @@ string Calibration::GetConnectionString() const


//______________________________________________________________________________
shared_ptr<Assignment> Calibration::GetAssignment(const string& namepath, bool loadColumns /*=true*/)
Assignment* Calibration::GetAssignment(const string& namepath, bool loadColumns /*=true*/)
{
/** @brief Gets the assignment from provider using namepath
* namepath is the common ccdb request; @see GetCalib
Expand All @@ -594,7 +594,7 @@ string Calibration::GetConnectionString() const
*/

auto pl = PerfLog("Calibration::GetAssignment=>" + namepath );
static std::map<std::string, shared_ptr<Assignment>> cache;
static std::map<std::string, Assignment*> cache;

UpdateActivityTime();

Expand All @@ -620,15 +620,15 @@ string Calibration::GetConnectionString() const
}
}

shared_ptr<Assignment> assigment;
Assignment* assigment;

if(time > 0)
{
assigment = shared_ptr<Assignment>(mProvider->GetAssignmentShort(run, PathUtils::MakeAbsolute(result.Path), time, variation,loadColumns));
assigment = (mProvider->GetAssignmentShort(run, PathUtils::MakeAbsolute(result.Path), time, variation,loadColumns));
}
else
{
assigment = shared_ptr<Assignment>(mProvider->GetAssignmentShort(run, PathUtils::MakeAbsolute(result.Path), variation,loadColumns));
assigment = (mProvider->GetAssignmentShort(run, PathUtils::MakeAbsolute(result.Path), variation,loadColumns));
}

if(mIsCacheEnabled)
Expand Down
18 changes: 17 additions & 1 deletion src/Tests/test_NoMySqlUserAPI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ TEST_CASE("CCDB/UserAPI/SQLite_CalibrationGenerator","Use universal generator to

SECTION("Get Assignment test", "Test all elements of getting data through get assignment")
{
std::shared_ptr<Assignment> a;
//std::shared_ptr<Assignment> a;
Assignment* a;
REQUIRE_NOTHROW(a = sqliteCalib->GetAssignment("/test/test_vars/test_table2:0:test"));
REQUIRE(result);
REQUIRE(a->GetValueType(0) == ConstantsTypeColumn::cIntColumn);
Expand All @@ -176,4 +177,19 @@ TEST_CASE("CCDB/UserAPI/SQLite_CalibrationGenerator","Use universal generator to
REQUIRE(a->GetValueInt(0, "c3") == 30);
REQUIRE(a->GetValueDouble(2) > 29);
}

//=== Default time ===
SECTION("Several Calibrations tear down SQLite", "Test that crash in destructor #45")
{
{
unique_ptr<CalibrationGenerator> gen2(new CalibrationGenerator());

ContextParseResult res = PathUtils::ParseContext("variation=default calibtime=2012-08");
unique_ptr<Calibration> sqliteCalib1(gen2->MakeCalibration(TESTS_SQLITE_STRING, 100, res.Variation, res.ConstantsTime));
//unique_ptr<Calibration> sqliteCalib2(gen2->MakeCalibration(TESTS_SQLITE_STRING, 100, res.Variation, res.ConstantsTime));
unique_ptr<Calibration> sqliteCalib3(gen2->MakeCalibration(TESTS_SQLITE_STRING, 101, res.Variation, res.ConstantsTime));
sqliteCalib1->GetAssignment("/test/test_vars/test_table2:0:test");
//Now lets check the teardown...
}
}
}

0 comments on commit 75d0573

Please sign in to comment.