Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
dd712841
Commit
dd712841
authored
Feb 10, 2017
by
peastman
Committed by
GitHub
Feb 10, 2017
Browse files
Merge pull request #1736 from peastman/leak
Fixed memory leaks when minimizer fails
parents
6231d53f
df6bbb23
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
262 additions
and
235 deletions
+262
-235
libraries/lbfgs/src/lbfgs.cpp
libraries/lbfgs/src/lbfgs.cpp
+192
-171
openmmapi/src/LocalEnergyMinimizer.cpp
openmmapi/src/LocalEnergyMinimizer.cpp
+70
-64
No files found.
libraries/lbfgs/src/lbfgs.cpp
View file @
dd712841
...
...
@@ -408,6 +408,7 @@ int lbfgs(
pf
=
(
lbfgsfloatval_t
*
)
vecalloc
(
param
.
past
*
sizeof
(
lbfgsfloatval_t
));
}
try
{
/* Evaluate the function value and its gradient. */
fx
=
cd
.
proc_evaluate
(
cd
.
instance
,
x
,
g
,
cd
.
n
,
0
);
if
(
0.
!=
param
.
orthantwise_c
)
{
...
...
@@ -613,6 +614,26 @@ int lbfgs(
*/
step
=
1.0
;
}
}
catch
(...)
{
vecfree
(
pf
);
/* Free memory blocks used by this function. */
if
(
lm
!=
NULL
)
{
for
(
i
=
0
;
i
<
m
;
++
i
)
{
vecfree
(
lm
[
i
].
s
);
vecfree
(
lm
[
i
].
y
);
}
vecfree
(
lm
);
}
vecfree
(
pg
);
vecfree
(
w
);
vecfree
(
d
);
vecfree
(
gp
);
vecfree
(
g
);
vecfree
(
xp
);
throw
;
}
lbfgs_exit:
/* Return the final value of the objective function. */
...
...
openmmapi/src/LocalEnergyMinimizer.cpp
View file @
dd712841
...
...
@@ -105,12 +105,13 @@ static lbfgsfloatval_t evaluate(void *instance, const lbfgsfloatval_t *x, lbfgsf
void
LocalEnergyMinimizer
::
minimize
(
Context
&
context
,
double
tolerance
,
int
maxIterations
)
{
const
System
&
system
=
context
.
getSystem
();
int
numParticles
=
system
.
getNumParticles
();
lbfgsfloatval_t
*
x
=
lbfgs_malloc
(
numParticles
*
3
);
if
(
x
==
NULL
)
throw
OpenMMException
(
"LocalEnergyMinimizer: Failed to allocate memory"
);
double
constraintTol
=
context
.
getIntegrator
().
getConstraintTolerance
();
double
workingConstraintTol
=
std
::
max
(
1e-4
,
constraintTol
);
double
k
=
tolerance
/
workingConstraintTol
;
lbfgsfloatval_t
*
x
=
lbfgs_malloc
(
numParticles
*
3
);
if
(
x
==
NULL
)
throw
OpenMMException
(
"LocalEnergyMinimizer: Failed to allocate memory"
);
try
{
// Initialize the minimizer.
...
...
@@ -182,6 +183,11 @@ void LocalEnergyMinimizer::minimize(Context& context, double tolerance, int maxI
}
}
}
}
catch
(...)
{
lbfgs_free
(
x
);
throw
;
}
lbfgs_free
(
x
);
// If necessary, do a final constraint projection to make sure they are satisfied
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment