Skip to content

Commit

Permalink
[ONNX Runtime] Fix OrtNDArray double close issue (deepjavalibrary#1861)
Browse files Browse the repository at this point in the history
  • Loading branch information
xyang16 authored and patins1 committed Aug 26, 2022
1 parent 5a43375 commit abe9b0f
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ public Shape getShape() {
/** {@inheritDoc} */
@Override
public void intern(NDArray replaced) {
tensor.getAndSet(((OrtNDArray) replaced).getTensor()).close();
OrtNDArray arr = (OrtNDArray) replaced;
OnnxTensor oldHandle = tensor.getAndSet(arr.tensor.getAndSet(null));
if (oldHandle != null) {
oldHandle.close();
}
replaced.close();
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -113,10 +118,10 @@ public ByteBuffer toByteBuffer() {
/** {@inheritDoc} */
@Override
public void close() {
super.close();
OnnxTensor ortTensor = tensor.getAndSet(null);
if (ortTensor != null) {
ortTensor.close();
}
super.close();
}
}

0 comments on commit abe9b0f

Please sign in to comment.