diff --git a/src/client/jni/com_taosdata_jdbc_TSDBJNIConnector.h b/src/client/jni/com_taosdata_jdbc_TSDBJNIConnector.h index 9f9632cadc3b0f8abb80d43f0eed87981f0db7c0..d99fca5ce130163d0f244305ca4466a5c033444d 100644 --- a/src/client/jni/com_taosdata_jdbc_TSDBJNIConnector.h +++ b/src/client/jni/com_taosdata_jdbc_TSDBJNIConnector.h @@ -9,6 +9,14 @@ extern "C" { #endif #undef com_taosdata_jdbc_TSDBJNIConnector_INVALID_CONNECTION_POINTER_VALUE #define com_taosdata_jdbc_TSDBJNIConnector_INVALID_CONNECTION_POINTER_VALUE 0LL +/* + * Class: com_taosdata_jdbc_TSDBJNIConnector + * Method: + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_detectMemoryLeakImp + (JNIEnv *, jclass, jstring); + /* * Class: com_taosdata_jdbc_TSDBJNIConnector * Method: initImp diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index d958679544093b54e4c5090557376ac8f96abc43..4123c2aa127c2d9eb8383ce371e1a08a92213782 100644 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -111,6 +111,18 @@ void jniGetGlobalMethod(JNIEnv *env) { jniTrace("native method register finished"); } +JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_detectMemoryLeakImp(JNIEnv *env, jobject jobj, jstring jPath) { + if (jPath != NULL) { + const char *path = (*env)->GetStringUTFChars(env, jPath, NULL); + taos_dump_memory_leak_at_exit(path); + (*env)->ReleaseStringUTFChars(env, jPath, path); + } else { + taos_dump_memory_leak_at_exit(NULL); + } + + jniGetGlobalMethod(env); +} + JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_initImp(JNIEnv *env, jobject jobj, jstring jconfigDir) { if (jconfigDir != NULL) { const char *confDir = (*env)->GetStringUTFChars(env, jconfigDir, NULL); diff --git a/src/util/src/tmem.c b/src/util/src/tmem.c index 3ca6cedf298053e0dc9bb2351e85e33a8c137cc1..81dff5504908e2d54e00a9fc8d2b2f5f374449c0 100644 --- a/src/util/src/tmem.c +++ b/src/util/src/tmem.c @@ -310,6 +310,11 @@ static void dump_memory_leak_at_sig(int sig) { } void taos_dump_memory_leak_at_exit(const char* path) { + if (fpMemLeak != NULL) { + printf("memory leak detection already enabled.\n"); + return; + } + if (path == NULL || path[0] == 0) { fpMemLeak = stdout; } else if ((fpMemLeak = fopen(path, "w")) == NULL) {