diff --git a/java/rocksjni/options.cc b/java/rocksjni/options.cc index 335b61861..4385085d0 100644 --- a/java/rocksjni/options.cc +++ b/java/rocksjni/options.cc @@ -1104,7 +1104,7 @@ std::vector rocksdb_compression_vector_helper( */ jbyteArray rocksdb_compression_list_helper(JNIEnv* env, std::vector compressionLevels) { - jbyte jbuf[compressionLevels.size()]; + std::unique_ptr jbuf = std::make_unique(compressionLevels.size()); for (std::vector::size_type i = 0; i != compressionLevels.size(); i++) { jbuf[i] = compressionLevels[i]; @@ -1113,7 +1113,7 @@ jbyteArray rocksdb_compression_list_helper(JNIEnv* env, jbyteArray jcompressionLevels = env->NewByteArray( static_cast(compressionLevels.size())); env->SetByteArrayRegion(jcompressionLevels, 0, - static_cast(compressionLevels.size()), jbuf); + static_cast(compressionLevels.size()), jbuf.get()); return jcompressionLevels; } diff --git a/java/rocksjni/rocksjni.cc b/java/rocksjni/rocksjni.cc index 8e93f09a4..6c064fd6d 100644 --- a/java/rocksjni/rocksjni.cc +++ b/java/rocksjni/rocksjni.cc @@ -115,14 +115,14 @@ jlongArray rocksdb_open_helper(JNIEnv* env, jlong jopt_handle, // check if open operation was successful if (s.ok()) { jsize resultsLen = 1 + len_cols; //db handle + column family handles - jlong results[resultsLen]; + std::unique_ptr results = std::make_unique(resultsLen); results[0] = reinterpret_cast(db); for(int i = 1; i <= len_cols; i++) { results[i] = reinterpret_cast(handles[i - 1]); } jlongArray jresults = env->NewLongArray(resultsLen); - env->SetLongArrayRegion(jresults, 0, resultsLen, results); + env->SetLongArrayRegion(jresults, 0, resultsLen, results.get()); return jresults; } else { rocksdb::RocksDBExceptionJni::ThrowNew(env, s); diff --git a/java/rocksjni/ttl.cc b/java/rocksjni/ttl.cc index 535bc10a0..8dc7280f0 100644 --- a/java/rocksjni/ttl.cc +++ b/java/rocksjni/ttl.cc @@ -12,6 +12,7 @@ #include #include #include +#include #include "include/org_rocksdb_TtlDB.h" #include "rocksdb/utilities/db_ttl.h" @@ -95,14 +96,14 @@ jlongArray // check if open operation was successful if (s.ok()) { jsize resultsLen = 1 + len_cols; //db handle + column family handles - jlong results[resultsLen]; + std::unique_ptr results = std::make_unique(resultsLen); results[0] = reinterpret_cast(db); for(int i = 1; i <= len_cols; i++) { results[i] = reinterpret_cast(handles[i - 1]); } jlongArray jresults = env->NewLongArray(resultsLen); - env->SetLongArrayRegion(jresults, 0, resultsLen, results); + env->SetLongArrayRegion(jresults, 0, resultsLen, results.get()); return jresults; } else { rocksdb::RocksDBExceptionJni::ThrowNew(env, s);