Skip to content

Commit 8f09f25

Browse files
SiegeLordExSiegeLord
authored andcommitted
Fix a memory leak.
1 parent ad050fc commit 8f09f25

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ impl Session {
320320
}
321321
}
322322

323+
// In case we're running it a second time and not all outputs were taken out.
324+
step.drop_output_tensors();
325+
323326
let status = Status::new();
324327
unsafe {
325328
tf::TF_Run(
@@ -458,10 +461,8 @@ impl<'l> Step<'l> {
458461
Some(DataType::from_int(mem::transmute(tf::TF_TensorType(self.output_tensors[output_idx]))))
459462
}
460463
}
461-
}
462464

463-
impl<'l> Drop for Step<'l> {
464-
fn drop(&mut self) {
465+
fn drop_output_tensors(&mut self) {
465466
for &tensor in &self.output_tensors {
466467
// TODO: Is TF_DeleteTensor NULL safe?
467468
if !tensor.is_null() {
@@ -473,6 +474,12 @@ impl<'l> Drop for Step<'l> {
473474
}
474475
}
475476

477+
impl<'l> Drop for Step<'l> {
478+
fn drop(&mut self) {
479+
self.drop_output_tensors();
480+
}
481+
}
482+
476483
////////////////////////
477484

478485
/// Convenience type for `Result` with `Status` as the error type.

0 commit comments

Comments
 (0)