diff options
author | Sergey Vojtovich <svoj@mariadb.org> | 2015-07-16 16:17:17 +0400 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2015-07-23 14:33:22 +0400 |
commit | d897015d74d82464a21ed154f606adc69503c372 (patch) | |
tree | 5ebf8366f96a0b8d5c8172c38629314018700142 /mysys/thr_lock.c | |
parent | cb3a71d238996ee6054fa6bb7cf47435d474dc55 (diff) | |
download | mariadb-git-d897015d74d82464a21ed154f606adc69503c372.tar.gz |
MDEV-8399 - [PATCH] Missing Sanity Checks for memory allocation in MariaDB
- since param is quite small store it on stack
- fixed a few memory leaks
Diffstat (limited to 'mysys/thr_lock.c')
-rw-r--r-- | mysys/thr_lock.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/mysys/thr_lock.c b/mysys/thr_lock.c index 1782aecd4df..8dce58dd58a 100644 --- a/mysys/thr_lock.c +++ b/mysys/thr_lock.c @@ -1726,7 +1726,7 @@ static void *test_thread(void *arg) thread_count--; mysql_cond_signal(&COND_thread_count); /* Tell main we are ready */ mysql_mutex_unlock(&LOCK_thread_count); - free((uchar*) arg); + my_thread_end(); return 0; } @@ -1735,7 +1735,7 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) { pthread_t tid; pthread_attr_t thr_attr; - int *param,error; + int param[array_elements(lock_counts)], error; uint i; MY_INIT(argv[0]); if (argc > 1 && argv[1][0] == '-' && argv[1][1] == '#') @@ -1791,8 +1791,7 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) #endif for (i=0 ; i < array_elements(lock_counts) ; i++) { - param=(int*) malloc(sizeof(int)); - *param=i; + param[i]= i; if ((error= mysql_mutex_lock(&LOCK_thread_count))) { @@ -1802,7 +1801,7 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) } if ((error= mysql_thread_create(0, &tid, &thr_attr, test_thread, - (void*) param))) + (void*) ¶m[i]))) { fprintf(stderr, "Got error: %d from mysql_thread_create (errno: %d)\n", error, errno); @@ -1831,6 +1830,9 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) else #endif printf("Test succeeded\n"); + mysql_cond_destroy(&COND_thread_count); + mysql_mutex_destroy(&LOCK_thread_count); + my_end(MY_CHECK_ERROR); return 0; } |