diff --git a/src/os/linux/src/os.c b/src/os/linux/src/os.c index 7d0305bb4f110719ffc5a3f4e435452a1f3ad2c3..785b1dd16e41618a1b9816ab40c18fa6c39bf5ea 100644 --- a/src/os/linux/src/os.c +++ b/src/os/linux/src/os.c @@ -223,28 +223,30 @@ int taosOpenUDServerSocket(char *ip, short port) { return sockFd; } +// The callback functions MUST free the param pass to it after finishing use it. int taosInitTimer(void *(*callback)(void *), int ms) { /******************************************************** * Create SIGALRM loop thread ********************************************************/ - pthread_t thread; + pthread_t thread; pthread_attr_t tattr; if (pthread_attr_init(&tattr)) { - return -1; + return -1; } if (pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED)) { - return -1; + return -1; } - int *tms = (int *)malloc(sizeof(int)); + int *tms = (int *) malloc(sizeof(int)); *tms = ms; - if (pthread_create(&thread, &tattr, callback, (void *)tms)) { - return -1; + if (pthread_create(&thread, &tattr, callback, (void *) tms)) { + free(tms); + return -1; } if (pthread_attr_destroy(&tattr)) { - return -1; + return -1; } return 0;