Skip to content

Commit 3d4c0ef

Browse files
committed
Fix: do not close NULL handle in generic case
1 parent 6caf36f commit 3d4c0ef

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/HPyExternalFunctionNodes.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,9 +768,12 @@ Object doGeneric(GraalHPyContext nativeContext, String name, Object value,
768768
@Shared("fact") @Cached PythonObjectFactory factory,
769769
@Shared("raiseNode") @Cached PRaiseNode raiseNode) {
770770
GraalHPyHandle handle = ensureHandleNode.execute(nativeContext, value);
771-
// Python land is receiving a handle from an HPy extension, so we are now owning the
772-
// handle and we don't need it any longer. So, close it in every case.
773-
handle.close(nativeContext, isAllocatedProfile);
771+
boolean isNullHandle = isNullHandle(nativeContext, handle);
772+
if (!isNullHandle) {
773+
// Python land is receiving a handle from an HPy extension, so we are now owning the
774+
// handle and we don't need it any longer. So, close it in every case.
775+
handle.close(nativeContext, isAllocatedProfile);
776+
}
774777
checkFunctionResult(name, isNullHandle(nativeContext, handle), nativeContext, raiseNode, factory, language);
775778
return asPythonObjectNode.execute(nativeContext, handle);
776779
}

0 commit comments

Comments
 (0)