diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/TruffleRLanguage.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/TruffleRLanguage.java
index 2c708749458aa496473e4daa4360cb53a350fc37..2f58d2ee6581dd3cd596ea0e234e6332c6a77efa 100644
--- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/TruffleRLanguage.java
+++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/TruffleRLanguage.java
@@ -41,6 +41,7 @@ import com.oracle.truffle.r.engine.interop.RForeignAccessFactoryImpl;
 import com.oracle.truffle.r.nodes.RASTBuilder;
 import com.oracle.truffle.r.nodes.builtin.RBuiltinPackages;
 import com.oracle.truffle.r.nodes.instrumentation.RSyntaxTags;
+import com.oracle.truffle.r.runtime.ExitException;
 import com.oracle.truffle.r.runtime.FastROptions;
 import com.oracle.truffle.r.runtime.RAccuracyInfo;
 import com.oracle.truffle.r.runtime.RError;
@@ -80,7 +81,17 @@ public final class TruffleRLanguage extends TruffleLanguage<RContext> {
 
         } catch (Throwable t) {
             t.printStackTrace();
-            Utils.rSuicide("error during R language initialization");
+            /*
+             * Truffle currently has no distinguished exception to indicate language initialization
+             * failure, so nothing good can come from throwing the exception, which is what
+             * Utils.rSuicide does. For now we catch it and exit the process.
+             */
+            try {
+                Utils.rSuicide("error during R language initialization");
+            } catch (ExitException ex) {
+                System.exit(ex.getStatus());
+            }
+
         }
     }
 
diff --git a/com.oracle.truffle.r.native/fficall/src/jni/base_rffi.c b/com.oracle.truffle.r.native/fficall/src/jni/base_rffi.c
index 0af58786b908555c60b933b7d7e42fb392c51a4d..6e19483674032eda9043ff7ae6e93bcdf963738e 100644
--- a/com.oracle.truffle.r.native/fficall/src/jni/base_rffi.c
+++ b/com.oracle.truffle.r.native/fficall/src/jni/base_rffi.c
@@ -58,11 +58,15 @@ Java_com_oracle_truffle_r_runtime_ffi_jni_JNI_1Base_native_1setwd(JNIEnv *env, j
 
 JNIEXPORT jint JNICALL
 Java_com_oracle_truffle_r_runtime_ffi_jni_JNI_1Base_native_1mkdtemp(JNIEnv *env, jclass c, jbyteArray jtemplate) {
-    char *template = (*env)->GetPrimitiveArrayCritical(env, jtemplate, NULL);
+    char *template = (char*) (*env)->GetByteArrayElements(env, jtemplate, NULL);
     char *r = mkdtemp(template);
-    if (r == NULL) return 0;
-    (*env)->ReleasePrimitiveArrayCritical(env, jtemplate, template, 0);
-    return 1;
+    int rc = 1;
+    if (r == NULL) {
+    	// printf("mkdtemp errno: %d\n", errno);
+    	rc = 0;
+    }
+    (*env)->ReleaseByteArrayElements(env, jtemplate, (jbyte*) template, rc == 1 ? 0 : JNI_ABORT);
+    return rc;
 }
 
 JNIEXPORT jint JNICALL
diff --git a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jni/JNI_Base.java b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jni/JNI_Base.java
index ca874253e76c4bbd00c8d568e7d74f6d9f32fd20..e07bf346aa6fdf5f41481dcbaf9f8b531fb958fa 100644
--- a/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jni/JNI_Base.java
+++ b/com.oracle.truffle.r.runtime.ffi/src/com/oracle/truffle/r/runtime/ffi/jni/JNI_Base.java
@@ -72,12 +72,19 @@ public class JNI_Base implements BaseRFFI {
 
     @Override
     public String mkdtemp(String template) {
+        /*
+         * Not only must the (C) string end in XXXXXX it must also be null-terminated. Since it is
+         * modified by mkdtemp we must make a copy.
+         */
         byte[] bytes = template.getBytes();
-        long result = native_mkdtemp(bytes);
+        byte[] ztbytes = new byte[bytes.length + 1];
+        System.arraycopy(bytes, 0, ztbytes, 0, bytes.length);
+        ztbytes[bytes.length] = 0;
+        long result = native_mkdtemp(ztbytes);
         if (result == 0) {
             return null;
         } else {
-            return new String(bytes);
+            return new String(ztbytes, 0, bytes.length);
         }
     }