Merge pull request #305 from H-ZeX/fix-mem-leak

fix memory leak in os/linux/src/os.c::taosInitTimer #304
This commit is contained in:
slguan 2019-08-10 23:52:37 +08:00 committed by GitHub
commit cfa7527c80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 7 deletions

View File

@ -223,6 +223,7 @@ int taosOpenUDServerSocket(char *ip, short port) {
return sockFd; return sockFd;
} }
// The callback functions MUST free the param pass to it after finishing use it.
int taosInitTimer(void *(*callback)(void *), int ms) { int taosInitTimer(void *(*callback)(void *), int ms) {
/******************************************************** /********************************************************
* Create SIGALRM loop thread * Create SIGALRM loop thread
@ -237,9 +238,10 @@ int taosInitTimer(void *(*callback)(void *), int ms) {
return -1; return -1;
} }
int *tms = (int *)malloc(sizeof(int)); int *tms = (int *) malloc(sizeof(int));
*tms = ms; *tms = ms;
if (pthread_create(&thread, &tattr, callback, (void *)tms)) { if (pthread_create(&thread, &tattr, callback, (void *) tms)) {
free(tms);
return -1; return -1;
} }