From 6b710893739839e05ea3ba390ac37ce6cee0066b Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Wed, 9 Jul 2014 13:34:15 +0200 Subject: [PATCH] Fix JVM segfault during JNI call. Part of [#2647] Motivation: Currently when Native.writev(...) is used it is possible to see a JVM segfault because the offset is updated to early. Modification: Only update the offset once it is safe to do so. Result: No more segfault --- .../src/main/c/io_netty_channel_epoll_Native.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/transport-native-epoll/src/main/c/io_netty_channel_epoll_Native.c b/transport-native-epoll/src/main/c/io_netty_channel_epoll_Native.c index bef1cedc89..3e14d27e7d 100644 --- a/transport-native-epoll/src/main/c/io_netty_channel_epoll_Native.c +++ b/transport-native-epoll/src/main/c/io_netty_channel_epoll_Native.c @@ -761,8 +761,6 @@ JNIEXPORT jlong JNICALL Java_io_netty_channel_epoll_Native_writev(JNIEnv * env, } w += res; - offset += loop; - length -= loop; // update the position of the written buffers int written = res; @@ -791,6 +789,8 @@ JNIEXPORT jlong JNICALL Java_io_netty_channel_epoll_Native_writev(JNIEnv * env, } } + offset += loop; + length -= loop; } return w; }