make 'taos_dump_memory_leak' public for java

This commit is contained in:
localvar 2019-11-14 09:51:45 +00:00
parent a5bfb0d670
commit 32abecfbc0
5 changed files with 33 additions and 11 deletions

View File

@ -17,6 +17,14 @@ extern "C" {
JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_detectMemoryLeakImp
(JNIEnv *, jclass, jstring);
/*
* Class: com_taosdata_jdbc_TSDBJNIConnector
* Method:
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_dumpMemoryLeakImp
(JNIEnv *, jclass);
/*
* Class: com_taosdata_jdbc_TSDBJNIConnector
* Method: initImp

View File

@ -114,15 +114,20 @@ void jniGetGlobalMethod(JNIEnv *env) {
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);
taos_detect_memory_leak(path);
(*env)->ReleaseStringUTFChars(env, jPath, path);
} else {
taos_dump_memory_leak_at_exit(NULL);
taos_detect_memory_leak(NULL);
}
jniGetGlobalMethod(env);
}
JNIEXPORT void JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_dumpMemoryLeakImp(JNIEnv *env, jobject jobj) {
taos_dump_memory_leak();
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);

View File

@ -187,7 +187,8 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, unsigned int inLen, cha
char *taosIpStr(uint32_t ipInt);
extern void taos_dump_memory_leak_at_exit(const char* path);
extern void taos_detect_memory_leak(const char* path);
extern void taos_dump_memory_leak();
#if TAOS_MEM_CHECK == 1

View File

@ -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_dump_memory_leak_at_exit(argv[++i]);
taos_detect_memory_leak(argv[++i]);
} else {
taos_dump_memory_leak_at_exit(NULL);
taos_detect_memory_leak(NULL);
}
#endif
}

View File

@ -261,11 +261,15 @@ ssize_t taos_getline(char **lineptr, size_t *n, FILE *stream, const char* file,
return size;
}
static void dump_memory_leak() {
void taos_dump_memory_leak() {
const char* hex = "0123456789ABCDEF";
const char* fmt = ":%d: addr=0x%p, size=%d, content(first 16 bytes)='";
size_t numOfBlk = 0, totalSize = 0;
if (fpMemLeak == NULL) {
return;
}
fputs("memory blocks allocated but not freed before exit:\n\n", fpMemLeak);
while (atomic_val_compare_exchange_ptr(&lock, 0, 1) != 0);
@ -303,13 +307,13 @@ static void dump_memory_leak() {
static void dump_memory_leak_at_sig(int sig) {
fprintf(fpMemLeak, "signal %d received, exiting...\n", sig);
dump_memory_leak();
taos_dump_memory_leak();
struct sigaction act = {0};
act.sa_handler = SIG_DFL;
sigaction(sig, &act, NULL);
}
void taos_dump_memory_leak_at_exit(const char* path) {
void taos_detect_memory_leak(const char* path) {
if (fpMemLeak != NULL) {
printf("memory leak detection already enabled.\n");
return;
@ -322,7 +326,7 @@ void taos_dump_memory_leak_at_exit(const char* path) {
return;
}
atexit(dump_memory_leak);
atexit(taos_dump_memory_leak);
struct sigaction act = {0};
act.sa_handler = dump_memory_leak_at_sig;
@ -334,7 +338,11 @@ void taos_dump_memory_leak_at_exit(const char* path) {
#endif
#if TAOS_MEM_CHECK != 2
void taos_dump_memory_leak_at_exit(const char* path) {
printf("memory leak detection not enabled!")
void taos_dump_memory_leak() {
// do nothing
}
void taos_detect_memory_leak(const char* path) {
printf("memory leak detection not enabled, please set 'TAOS_MEM_CHECK' to 2.");
}
#endif