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) { ...@@ -107,8 +107,10 @@ void CompoundIntegrator::initialize(ContextImpl& context) {
} }
void CompoundIntegrator::cleanup() { void CompoundIntegrator::cleanup() {
for (int i = 0; i < integrators.size(); i++) for (int i = 0; i < integrators.size(); i++) {
integrators[i]->cleanup(); integrators[i]->cleanup();
integrators[i]->context = nullptr;
}
} }
vector<string> CompoundIntegrator::getKernelNames() { vector<string> CompoundIntegrator::getKernelNames() {
......
...@@ -93,8 +93,9 @@ ContextImpl::ContextImpl(Context& owner, const System& system, Integrator& integ ...@@ -93,8 +93,9 @@ ContextImpl::ContextImpl(Context& owner, const System& system, Integrator& integ
// Validate the list of properties. // Validate the list of properties.
const vector<string>& platformProperties = platform->getPropertyNames();
map<string, string> validatedProperties; map<string, string> validatedProperties;
if (platform != NULL) {
const vector<string>& platformProperties = platform->getPropertyNames();
for (auto& prop : properties) { for (auto& prop : properties) {
string property = prop.first; string property = prop.first;
if (platform->deprecatedPropertyReplacements.find(property) != platform->deprecatedPropertyReplacements.end()) if (platform->deprecatedPropertyReplacements.find(property) != platform->deprecatedPropertyReplacements.end())
...@@ -109,6 +110,10 @@ ContextImpl::ContextImpl(Context& owner, const System& system, Integrator& integ ...@@ -109,6 +110,10 @@ ContextImpl::ContextImpl(Context& owner, const System& system, Integrator& integ
throw OpenMMException("Illegal property name: "+prop.first); throw OpenMMException("Illegal property name: "+prop.first);
validatedProperties[property] = prop.second; validatedProperties[property] = prop.second;
} }
}
else {
// There can't be any platform-specific properties if there's no platform
}
// Find the list of kernels required. // Find the list of kernels required.
......
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