Github user vanzin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18392#discussion_r123602210
  
    --- Diff: 
common/network-common/src/main/java/org/apache/spark/network/sasl/SparkSaslServer.java
 ---
    @@ -187,14 +188,26 @@ public void handle(Callback[] callbacks) throws 
IOException, UnsupportedCallback
       /* Encode a byte[] identifier as a Base64-encoded string. */
       public static String encodeIdentifier(String identifier) {
         Preconditions.checkNotNull(identifier, "User cannot be null if SASL is 
enabled");
    -    return 
Base64.encode(Unpooled.wrappedBuffer(identifier.getBytes(StandardCharsets.UTF_8)))
    -      .toString(StandardCharsets.UTF_8);
    +    return getBase64EncodedString(identifier);
       }
     
       /** Encode a password as a base64-encoded char[] array. */
       public static char[] encodePassword(String password) {
         Preconditions.checkNotNull(password, "Password cannot be null if SASL 
is enabled");
    -    return 
Base64.encode(Unpooled.wrappedBuffer(password.getBytes(StandardCharsets.UTF_8)))
    -      .toString(StandardCharsets.UTF_8).toCharArray();
    +    return getBase64EncodedString(password).toCharArray();
    +  }
    +
    +  /** Return a Base64-encoded string. */
    +  private static String getBase64EncodedString (String str) {
    +    ByteBuf byteBuf = null, encodedByteBuf = null;
    +    try {
    +      byteBuf = 
Unpooled.wrappedBuffer(str.getBytes(StandardCharsets.UTF_8));
    +      encodedByteBuf = Base64.encode(byteBuf);
    +      return encodedByteBuf.toString(StandardCharsets.UTF_8);
    +    } finally {
    +      // The release is called to suppress the memory leak error messages 
raised by netty.
    +      byteBuf.release();
    --- End diff --
    
    Well, it also makes the code more correct. Source analysis tools have a 
tendency to flag this kind of stuff. I don't see what's the problem with adding 
the checks.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to