Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
normanmaurer committed Mar 29, 2017
1 parent a5fe8d9 commit 8960e1e
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion openssl-dynamic/src/main/c/jnilib.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ JNIEXPORT void JNICALL JNI_OnUnload_netty_tcnative(JavaVM *vm, void *reserved)
TCN_UNLOAD_CLASS(env, keyMaterialClass);

// Unload everything that is related to SSL
tcn_ssl_unload();
ssl_init_cleanup();
}

/* Called by the JVM before the APR_JAVA is unloaded */
Expand Down
17 changes: 6 additions & 11 deletions openssl-dynamic/src/main/c/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ static void ssl_dyn_destroy_function(struct CRYPTO_dynlock_value *l,
free(l);
}

static void ssl_init_cleanup()
void ssl_init_cleanup()
{
int i;

Expand Down Expand Up @@ -697,7 +697,7 @@ static ENGINE *ssl_try_load_engine(const char *engine)
}
#endif

TCN_IMPLEMENT_CALL(jint, SSL, initialize)(TCN_STDARGS, jstring engine)
TCN_IMPLEMENT_CALL(void, SSL, initialize)(TCN_STDARGS, jstring engine)
{
int r = 0;
int i;
Expand All @@ -709,15 +709,15 @@ TCN_IMPLEMENT_CALL(jint, SSL, initialize)(TCN_STDARGS, jstring engine)
/* Check if already initialized */
if (ssl_initialized++) {
TCN_FREE_CSTRING(engine);
return 0;
return;
}

#if OPENSSL_VERSION_NUMBER < 0x10100000L
if (SSLeay() < 0x0090700L) {
TCN_FREE_CSTRING(engine);
tcn_ThrowException(e, "openssl version too old");
ssl_initialized = 0;
return -1;
return;
}
#endif

Expand Down Expand Up @@ -782,7 +782,7 @@ TCN_IMPLEMENT_CALL(jint, SSL, initialize)(TCN_STDARGS, jstring engine)
TCN_FREE_CSTRING(engine);
ssl_init_cleanup();
tcn_ThrowException(e, "Unable to init SSL");
return (jint)err;
return;
}
tcn_ssl_engine = ee;
}
Expand All @@ -801,11 +801,9 @@ TCN_IMPLEMENT_CALL(jint, SSL, initialize)(TCN_STDARGS, jstring engine)
TCN_FREE_CSTRING(engine);
ssl_init_cleanup();
tcn_ThrowException(e, "Unable to init SSL");
return -1;
return;
}
TCN_FREE_CSTRING(engine);

return 0;
}

TCN_IMPLEMENT_CALL(jlong, SSL, newMemBIO)(TCN_STDARGS)
Expand Down Expand Up @@ -2044,6 +2042,3 @@ TCN_IMPLEMENT_CALL(jbyteArray, SSL, getOcspResponse)(TCN_STDARGS, jlong ssl) {
#endif
}

void tcn_ssl_unload() {
ssl_init_cleanup();
}
10 changes: 5 additions & 5 deletions openssl-dynamic/src/main/c/sslcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ static void ssl_context_cleanup(tcn_ssl_ctxt_t *c)
c->password = NULL;
}

tcn_atomic_uint32_free(&(c->ticket_keys_new));
tcn_atomic_uint32_free(&(c->ticket_keys_resume));
tcn_atomic_uint32_free(&(c->ticket_keys_renew));
tcn_atomic_uint32_free(&(c->ticket_keys_fail));
tcn_atomic_uint32_free(&c->ticket_keys_new);
tcn_atomic_uint32_free(&c->ticket_keys_resume);
tcn_atomic_uint32_free(&c->ticket_keys_renew);
tcn_atomic_uint32_free(&c->ticket_keys_fail);

free(c);
}
Expand Down Expand Up @@ -321,7 +321,7 @@ TCN_IMPLEMENT_CALL(jlong, SSLContext, make)(TCN_STDARGS, jint protocol, jint mod
return P2J(c);
cleanup:
if (c != NULL) {
OPENSSL_free(c);
free(c);
}
SSL_CTX_free(ctx); // this function is safe to call with NULL.
return 0;
Expand Down
2 changes: 1 addition & 1 deletion openssl-dynamic/src/main/c/tcn.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void tcn_Throw(JNIEnv *, const char *, ...);
void tcn_ThrowException(JNIEnv *, const char *);
jstring tcn_new_string(JNIEnv *, const char *);
jstring tcn_new_stringn(JNIEnv *, const char *, size_t);
void tcn_ssl_unload();
void ssl_init_cleanup();

#define J2S(V) c##V
#define J2L(V) p##V
Expand Down
4 changes: 2 additions & 2 deletions openssl-dynamic/src/main/c/tcn_atomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ tcn_atomic_uint32_t tcn_atomic_uint32_new() {

void tcn_atomic_uint32_free(tcn_atomic_uint32_t* atomic) {
delete (std::atomic<uint32_t> *) *atomic;
*atomic = NULL;
*atomic = nullptr;
}

uint32_t tcn_atomic_uint32_get(tcn_atomic_uint32_t atomic) {
return *((std::atomic<uint32_t> *) atomic);
return *((std::atomic<uint32_t> *) atomic);
}

void tcn_atomic_uint32_increment(tcn_atomic_uint32_t atomic) {
Expand Down
4 changes: 3 additions & 1 deletion openssl-dynamic/src/main/c/tcn_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
#ifndef TCN_ATOMIC_H
#define TCN_ATOMIC_H

#include <stdint.h>

#ifdef __cplusplus
#include <cstdint>
extern "C" {
#else
#include <stdint.h>
#endif // __cplusplus

typedef void* tcn_atomic_uint32_t;
Expand Down
2 changes: 1 addition & 1 deletion openssl-dynamic/src/main/c/tcn_lock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tcn_lock_t tcn_lock_new() {

void tcn_lock_free(tcn_lock_t* lock) {
delete (std::mutex *) *lock;
*lock = NULL;
*lock = nullptr;
}

void tcn_lock_acquire(tcn_lock_t lock) {
Expand Down
2 changes: 1 addition & 1 deletion openssl-dynamic/src/main/c/tcn_lock_rw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ tcn_lock_rw_t tcn_lock_rw_new() {

void tcn_lock_rw_free(tcn_lock_rw_t* lock) {
delete (std::shared_timed_mutex *) *lock;
*lock = NULL;
*lock = nullptr;
}

tcn_lock_w_t tcn_lock_w_acquire(tcn_lock_rw_t lock) {
Expand Down
4 changes: 3 additions & 1 deletion openssl-dynamic/src/main/c/tcn_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
#ifndef TCN_THREAD_H
#define TCN_THREAD_H

#include <stddef.h>

#ifdef __cplusplus
#include <cstddef>
extern "C" {
#else
#include <stddef.h>
#endif // __cplusplus

size_t tcn_current_thread_id();
Expand Down

0 comments on commit 8960e1e

Please sign in to comment.