Unverified Commit ae1b02dc authored by Dann239's avatar Dann239 Committed by GitHub
Browse files

Fix for nullptr dereferencing that caused test failures (#3527)



* Prevent child integrators from accessing deleted context

* Prevent reading property names from nullptr platform

* Don't check properties in a loop, but only when there's a Platform

* Clarified condition in "if" block
Co-authored-by: default avatarPeter Eastman <peter.eastman@gmail.com>
parent 79740ece
......@@ -107,8 +107,10 @@ void CompoundIntegrator::initialize(ContextImpl& context) {
}
void CompoundIntegrator::cleanup() {
for (int i = 0; i < integrators.size(); i++)
for (int i = 0; i < integrators.size(); i++) {
integrators[i]->cleanup();
integrators[i]->context = nullptr;
}
}
vector<string> CompoundIntegrator::getKernelNames() {
......
......@@ -93,23 +93,28 @@ ContextImpl::ContextImpl(Context& owner, const System& system, Integrator& integ
// Validate the list of properties.
const vector<string>& platformProperties = platform->getPropertyNames();
map<string, string> validatedProperties;
for (auto& prop : properties) {
string property = prop.first;
if (platform->deprecatedPropertyReplacements.find(property) != platform->deprecatedPropertyReplacements.end())
property = platform->deprecatedPropertyReplacements[property];
bool valid = false;
for (auto& p : platformProperties)
if (p == property) {
valid = true;
break;
}
if (!valid)
throw OpenMMException("Illegal property name: "+prop.first);
validatedProperties[property] = prop.second;
if (platform != NULL) {
const vector<string>& platformProperties = platform->getPropertyNames();
for (auto& prop : properties) {
string property = prop.first;
if (platform->deprecatedPropertyReplacements.find(property) != platform->deprecatedPropertyReplacements.end())
property = platform->deprecatedPropertyReplacements[property];
bool valid = false;
for (auto& p : platformProperties)
if (p == property) {
valid = true;
break;
}
if (!valid)
throw OpenMMException("Illegal property name: "+prop.first);
validatedProperties[property] = prop.second;
}
}
else {
// There can't be any platform-specific properties if there's no platform
}
// Find the list of kernels required.
vector<string> kernelNames;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment