提交 fc6737ab 编写于 作者: weixin_48148422's avatar weixin_48148422

add option 'autoDump' for memory leak detection.

上级 32abecfb
......@@ -15,7 +15,7 @@ extern "C" {
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_detectMemoryLeakImp
(JNIEnv *, jclass, jstring);
(JNIEnv *, jclass, jstring, jboolean);
/*
* Class: com_taosdata_jdbc_TSDBJNIConnector
......
......@@ -111,13 +111,13 @@ void jniGetGlobalMethod(JNIEnv *env) {
jniTrace("native method register finished");
}
JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_detectMemoryLeakImp(JNIEnv *env, jobject jobj, jstring jPath) {
JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_detectMemoryLeakImp(JNIEnv *env, jobject jobj, jstring jPath, jboolean jAutoDump) {
if (jPath != NULL) {
const char *path = (*env)->GetStringUTFChars(env, jPath, NULL);
taos_detect_memory_leak(path);
taos_detect_memory_leak(path, !!jAutoDump);
(*env)->ReleaseStringUTFChars(env, jPath, path);
} else {
taos_detect_memory_leak(NULL);
taos_detect_memory_leak(NULL, !!jAutoDump);
}
jniGetGlobalMethod(env);
......
......@@ -187,7 +187,7 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, unsigned int inLen, cha
char *taosIpStr(uint32_t ipInt);
extern void taos_detect_memory_leak(const char* path);
extern void taos_detect_memory_leak(const char* path, bool autoDump);
extern void taos_dump_memory_leak();
#if TAOS_MEM_CHECK == 1
......
......@@ -64,9 +64,9 @@ int main(int argc, char *argv[]) {
#if TAOS_MEM_CHECK == 2
} else if (strcmp(argv[i], "--check-mem-leak") == 0) {
if ((i < argc - 1) && (argv[i+1][0] != '-')) {
taos_detect_memory_leak(argv[++i]);
taos_detect_memory_leak(argv[++i], true);
} else {
taos_detect_memory_leak(NULL);
taos_detect_memory_leak(NULL, true);
}
#endif
}
......
......@@ -307,13 +307,15 @@ void taos_dump_memory_leak() {
static void dump_memory_leak_at_sig(int sig) {
fprintf(fpMemLeak, "signal %d received, exiting...\n", sig);
taos_dump_memory_leak();
struct sigaction act = {0};
act.sa_handler = SIG_DFL;
sigaction(sig, &act, NULL);
taos_dump_memory_leak();
}
void taos_detect_memory_leak(const char* path) {
void taos_detect_memory_leak(const char* path, bool autoDump) {
if (fpMemLeak != NULL) {
printf("memory leak detection already enabled.\n");
return;
......@@ -326,13 +328,14 @@ void taos_detect_memory_leak(const char* path) {
return;
}
atexit(taos_dump_memory_leak);
struct sigaction act = {0};
act.sa_handler = dump_memory_leak_at_sig;
sigaction(SIGFPE, &act, NULL);
sigaction(SIGSEGV, &act, NULL);
sigaction(SIGILL, &act, NULL);
if (autoDump) {
atexit(taos_dump_memory_leak);
struct sigaction act = {0};
act.sa_handler = dump_memory_leak_at_sig;
sigaction(SIGFPE, &act, NULL);
sigaction(SIGSEGV, &act, NULL);
sigaction(SIGILL, &act, NULL);
}
}
#endif
......@@ -342,7 +345,7 @@ void taos_dump_memory_leak() {
// do nothing
}
void taos_detect_memory_leak(const char* path) {
void taos_detect_memory_leak(const char* path, bool autoDump) {
printf("memory leak detection not enabled, please set 'TAOS_MEM_CHECK' to 2.");
}
#endif
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册