summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorBrian Carlstrom <bdc@google.com>2010-05-06 00:23:21 -0700
committerBrian Carlstrom <bdc@google.com>2010-05-06 16:27:37 -0700
commit3e24c53ecc31b840e51869c295785d5a2f8b31eb (patch)
tree0467469d8213d16b074626859ac9e77b3bd001cb /include
parentab3683bce6e370c946598bfad54387fa38ce69df (diff)
downloadlibcore-3e24c53ecc31b840e51869c295785d5a2f8b31eb.zip
libcore-3e24c53ecc31b840e51869c295785d5a2f8b31eb.tar.gz
libcore-3e24c53ecc31b840e51869c295785d5a2f8b31eb.tar.bz2
Moving OpenSSLSocketImpl native code to NativeCrypto (and other clearnup)
Summary: - Finished consolidating OpenSSL native code into NativeCrypto - fixing local vs global ref bug with AppData Added new ScopedGlobalRef as part of this fix - fixed many historical memory leaks identified during code review - fixed lack of error checking on allcoation with OpenSSL *_new routines - Added to_SSL_CTX and to_SSL_SESSION to match to_SSL (renamed from getSslPointer) - Replaced most uses of GetByteArrayElements with ScopedByteArray (including cases where we we using ReleaseByteArrayElements(..,...,0) instead of JNI_ABORT) - Replaced uses of GetStringUTFChars with ScopedUtfChars Details: Finished consolidating OpenSSL native code into NativeCrypto OpenSSLSocketImpl NativeCrypto --------------------------------------- nativeread SSL_read_byte nativeread SSL_read nativewrite SSL_write_byte nativewrite SSL_write nativeinterrupt SSL_interrupt nativeclose SSL_shutdown nativeverifysignature verifysignature Also removed dead code that was wrapping SSL_get1_session luni/src/main/java/org/apache/harmony/xnet/provider/jsse/NativeCrypto.java luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java luni/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp Fixed NativeCrypto_SSL_write and NativeCrypto_d2i_SSL_SESSION to use JNI_ABORT on release to avoid copy back of unchanged data (via ScopedByteArray). luni/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp While running the usual tests: adb shell run-core-tests tests.xnet.AllTests javax.net.ssl.AllTests there was an abort from the JNI checking because in the recent handshaking change, local refs were kept in AppData and then reused in later calls. Added new ScopedGlobalRef to handle the book keeping of this. luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java include/ScopedGlobalRef.h Fixed various leaks on old error paths spotted by reviewer. luni/src/main/native/org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp Tracking move of verifySignature, a non-SSL bit of code that was lurking in OpenSSLSocketImpl luni/src/main/java/org/apache/harmony/security/provider/cert/X509CertImpl.java Change-Id: If1e409782bc99dc684039cfe3f53f8244e29346e
Diffstat (limited to 'include')
-rw-r--r--include/ScopedGlobalRef.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/include/ScopedGlobalRef.h b/include/ScopedGlobalRef.h
new file mode 100644
index 0000000..15a9055
--- /dev/null
+++ b/include/ScopedGlobalRef.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SCOPED_GLOBAL_REF_H_included
+#define SCOPED_GLOBAL_REF_H_included
+
+#include "JNIHelp.h"
+
+// A smart pointer that provides access to a JNI global reference
+class ScopedGlobalRef {
+public:
+ ScopedGlobalRef(JNIEnv* env, jobject localRef)
+ : mEnv(env), mGlobalRef(NULL)
+ {
+ mGlobalRef = env->NewGlobalRef(localRef);
+ }
+
+ ~ScopedGlobalRef() {
+ reset();
+ }
+
+ void reset() {
+ if (mGlobalRef != NULL) {
+ mEnv->DeleteGlobalRef(mGlobalRef);
+ mGlobalRef = NULL;
+ }
+ }
+
+ jobject get () const {
+ return mGlobalRef;
+ }
+
+private:
+ JNIEnv* mEnv;
+ jobject mGlobalRef;
+
+ // Disallow copy and assignment.
+ ScopedGlobalRef(const ScopedGlobalRef&);
+ void operator=(const ScopedGlobalRef&);
+};
+
+#endif // SCOPED_GLOBAL_REF_H_included