Solve the memory leak in the JNI methods of protocols.