Skip to content

Commit 9bd325c

Browse files
committed
Throw exception on unaligned handle allocation.
1 parent 6a69671 commit 9bd325c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/main/java/org/truffleruby/cext/ValueWrapperManager.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.truffleruby.collections.LongHashMap;
1717
import org.truffleruby.extra.ffi.Pointer;
1818
import org.truffleruby.language.NotProvided;
19-
2019
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
2120
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
2221
import com.oracle.truffle.api.object.DynamicObject;
@@ -107,8 +106,11 @@ public synchronized void removeFromHandleMap(long handle) {
107106

108107
@TruffleBoundary
109108
public synchronized long createNativeHandle(DynamicObject wrapper) {
110-
Pointer handlePointer = Pointer.malloc(8);
109+
Pointer handlePointer = Pointer.malloc(1);
111110
long handleAddress = handlePointer.getAddress();
111+
if ((handleAddress & 0x7) != 0) {
112+
throw new RuntimeException("unaligned malloc for native handle");
113+
}
112114
Layouts.VALUE_WRAPPER.setHandle(wrapper, handleAddress);
113115
addToHandleMap(handleAddress, wrapper);
114116
addFinalizer(wrapper, handlePointer);

0 commit comments

Comments
 (0)