From fa8f967852c04fd99ae15ee2bd1047595a97417e Mon Sep 17 00:00:00 2001 From: Scott Mitchell Date: Tue, 3 Jul 2018 20:30:12 -0700 Subject: [PATCH] netty_unix_socket free nettyClassName after using it Motivation: netty_unix_socket attempts to use nettyClassName in an error message, but previously freed the memory. We should wait to free the memory until after we use it. Modifications: - Free nettyClassName after using it in snprintf Result: More useful error message. --- .../src/main/c/netty_unix_socket.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/transport-native-unix-common/src/main/c/netty_unix_socket.c b/transport-native-unix-common/src/main/c/netty_unix_socket.c index 380fcda24a..3dd0920b19 100644 --- a/transport-native-unix-common/src/main/c/netty_unix_socket.c +++ b/transport-native-unix-common/src/main/c/netty_unix_socket.c @@ -1028,16 +1028,20 @@ jint netty_unix_socket_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) { // Respect shading... char parameters[1024] = {0}; snprintf(parameters, sizeof(parameters), "(Ljava/lang/String;IIL%s;)V", nettyClassName); - free(nettyClassName); - nettyClassName = NULL; datagramSocketAddrMethodId = (*env)->GetMethodID(env, datagramSocketAddressClass, "", parameters); if (datagramSocketAddrMethodId == NULL) { char msg[1024] = {0}; snprintf(msg, sizeof(msg), "failed to get method ID: %s.(String, int, int, %s)", nettyClassName, nettyClassName); + free(nettyClassName); + nettyClassName = NULL; netty_unix_errors_throwRuntimeException(env, msg); return JNI_ERR; } + + free(nettyClassName); + nettyClassName = NULL; + jclass localInetSocketAddressClass = (*env)->FindClass(env, "java/net/InetSocketAddress"); if (localInetSocketAddressClass == NULL) { // pending exception...