toddlipcon commented on a change in pull request #600: HDFS-14348: Fix JNI 
exception handling issues in libhdfs
URL: https://github.com/apache/hadoop/pull/600#discussion_r267627222
 
 

 ##########
 File path: 
hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c
 ##########
 @@ -2512,17 +2509,35 @@ int hadoopRzOptionsSetByteBufferPool(
       if (jthr) {
           printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
               "hadoopRzOptionsSetByteBufferPool(className=%s): ", className);
-          errno = EINVAL;
-          return -1;
+          ret = EINVAL;
+          goto done;
       }
-      opts->byteBufferPool = (*env)->NewGlobalRef(env, byteBufferPool);
-      if (!opts->byteBufferPool) {
-          printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
+      // Only set opts->byteBufferPool if creating a global reference is
+      // successful
+      globalByteBufferPool = (*env)->NewGlobalRef(env, byteBufferPool);
+      if (!globalByteBufferPool) {
+          printPendingExceptionAndFree(env, PRINT_EXC_ALL,
                   "hadoopRzOptionsSetByteBufferPool(className=%s): ",
                   className);
-          errno = EINVAL;
-          return -1;
+          ret = EINVAL;
+          goto done;
+      }
+      // Delete any previous ByteBufferPool we had before setting a new one.
+      if (opts->byteBufferPool) {
+          (*env)->DeleteGlobalRef(env, opts->byteBufferPool);
       }
+      opts->byteBufferPool = globalByteBufferPool;
+    } else if (opts->byteBufferPool) {
+        // If the specified className is NULL, delete any previous
+        // ByteBufferPool we had.
+        (*env)->DeleteGlobalRef(env, opts->byteBufferPool);
 
 Review comment:
   need to also set it back to null, right?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to