summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2021-01-21 12:23:14 +0100
committerArne Schwabe <arne@rfc2549.org>2021-02-16 16:40:04 +0100
commita965f961b5dc5cba44d9a81a538c11c4394de24e (patch)
tree4c8ff0aa02ac4c740c4b7579c9c7b1b975e38419
parent4d3306f2b5f009ea7d7d82ef06d29ad461d2a4cf (diff)
Fix very unlikely ressource leaks
-rw-r--r--main/src/main/cpp/opvpnutil/scan_ifs.c4
-rw-r--r--main/src/main/cpp/opvpnutil/sslspeed.c14
2 files changed, 12 insertions, 6 deletions
diff --git a/main/src/main/cpp/opvpnutil/scan_ifs.c b/main/src/main/cpp/opvpnutil/scan_ifs.c
index a26e2b36..85021d88 100644
--- a/main/src/main/cpp/opvpnutil/scan_ifs.c
+++ b/main/src/main/cpp/opvpnutil/scan_ifs.c
@@ -16,8 +16,7 @@
jobjectArray Java_de_blinkt_openvpn_core_NativeUtils_getIfconfig(JNIEnv* env)
{
-
- int sd;
+ int sd;
if ((sd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) {
__android_log_print(ANDROID_LOG_DEBUG, "openvpn", "Opening socket for intface get failed");
//jniThrowException(env, "java/lang/IllegalArgumentException", "Opening socket for intface get failed");
@@ -33,6 +32,7 @@ jobjectArray Java_de_blinkt_openvpn_core_NativeUtils_getIfconfig(JNIEnv* env)
if (ioctl (sd, SIOCGIFCONF, &ifc) < 0) {
__android_log_print(ANDROID_LOG_DEBUG, "openvpn", "IOCTL for intface get failed");
//jniThrowException(env, "java/lang/IllegalArgumentException", "IOTCL socket for intface get failed");
+ close(sd);
return NULL;
}
diff --git a/main/src/main/cpp/opvpnutil/sslspeed.c b/main/src/main/cpp/opvpnutil/sslspeed.c
index 0ce9ede2..1881998e 100644
--- a/main/src/main/cpp/opvpnutil/sslspeed.c
+++ b/main/src/main/cpp/opvpnutil/sslspeed.c
@@ -206,7 +206,7 @@ static void* stop_run(void* arg)
return NULL;
}
- jdoubleArray Java_de_blinkt_openvpn_core_NativeUtils_getOpenSSLSpeed(JNIEnv* env, jclass thiz, jstring algorithm, jint testnumber)
+jdoubleArray Java_de_blinkt_openvpn_core_NativeUtils_getOpenSSLSpeed(JNIEnv* env, jclass thiz, jstring algorithm, jint testnumber)
{
static const unsigned char key16[16] = {
0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0,
@@ -238,7 +238,7 @@ static void* stop_run(void* arg)
jdoubleArray ret = (*env)->NewDoubleArray(env, 3);
if (testnum < 0 || testnum >= SIZE_NUM)
- return NULL;
+ goto error;
testnum = testnumber;
@@ -276,7 +276,7 @@ static void* stop_run(void* arg)
pthread_t timer_thread;
if (pthread_create(&timer_thread, NULL, stop_run, NULL))
- return NULL;
+ goto error;
count = run_benchmark(async_jobs, EVP_Update_loop, loopargs);
d = Time_F(STOP);
@@ -290,7 +290,7 @@ static void* stop_run(void* arg)
pthread_t timer_thread;
if (pthread_create(&timer_thread, NULL, stop_run, NULL))
- return NULL;
+ goto error;
Time_F(START);
count = run_benchmark(async_jobs, EVP_Digest_loop, loopargs);
@@ -306,4 +306,10 @@ static void* stop_run(void* arg)
return ret;
+error:
+ free(loopargs);
+ for (int k = 0; k < loopargs_len; k++) {
+ EVP_CIPHER_CTX_free(loopargs[k].ctx);
+ }
+ return NULL;
}