Skip to content

Commit

Permalink
Check CallbackReference#cbstruct for null when checking existing Refe…
Browse files Browse the repository at this point in the history
…rence

The CallbackReference is held in a WeahHashMap, where it might be
removed from when it becomes eligable for GC. For this there is a null
guard in place, but when the callback reference is explicitly closed,
the associated native structure is freed and "nulled", this case also
needs to be guarded.
  • Loading branch information
matthiasblaesing committed Mar 8, 2024
1 parent 16e036a commit 6486c90
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/com/sun/jna/CallbackReference.java
Expand Up @@ -508,7 +508,7 @@ private static Pointer getFunctionPointer(Callback cb, boolean direct) {
Map<Callback, CallbackReference> map = direct ? directCallbackMap : callbackMap;
synchronized(pointerCallbackMap) {
CallbackReference cbref = map.get(cb);
if (cbref == null) {
if (cbref == null || cbref.cbstruct == null) {
cbref = new CallbackReference(cb, callingConvention, direct);
map.put(cb, cbref);
pointerCallbackMap.put(cbref.getTrampoline(),
Expand Down

0 comments on commit 6486c90

Please sign in to comment.