Skip to content

Commit 3ab2d21

Browse files
committed
FMArray : fix leaks
1 parent 922c4e8 commit 3ab2d21

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/javaforce/ffm/FFMArray.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,43 @@ private long pin() {
2222
return ptr;
2323
}
2424

25+
private void unpin() {
26+
JFNative.unpin(ref, ptr, true);
27+
ptr = 0;
28+
}
29+
2530
public long NewByteArray(int size) {
31+
if (ptr != 0) unpin();
2632
ref = new byte[size];
2733
return pin();
2834
}
2935

3036
public long NewShortArray(int size) {
37+
if (ptr != 0) unpin();
3138
ref = new short[size];
3239
return pin();
3340
}
3441

3542
public long NewIntArray(int size) {
43+
if (ptr != 0) unpin();
3644
ref = new int[size];
3745
return pin();
3846
}
3947

4048
public long NewLongArray(int size) {
49+
if (ptr != 0) unpin();
4150
ref = new long[size];
4251
return pin();
4352
}
4453

4554
public long NewFloatArray(int size) {
55+
if (ptr != 0) unpin();
4656
ref = new float[size];
4757
return pin();
4858
}
4959

5060
public long NewStringArray(int size) {
61+
if (ptr != 0) unpin();
5162
ref = new String[size];
5263
return pin();
5364
}
@@ -61,10 +72,7 @@ public void SetStringElement(int idx, MemorySegment str) {
6172

6273
public Object getArray() {
6374
if (ref == null) return null;
64-
if (ptr != 0) {
65-
JFNative.unpin(ref, ptr, true);
66-
ptr = 0;
67-
}
75+
if (ptr != 0) unpin();
6876
return ref;
6977
}
7078

0 commit comments

Comments
 (0)