From: David Sterba Date: Wed, 2 Nov 2016 23:57:43 +0000 (+0100) Subject: btrfs-progs: image: use fixed-size array for worker thread pointers X-Git-Tag: upstream/4.16.1~1083 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=acd258077795a2f1fd9104893d81552a3db4f012;p=platform%2Fupstream%2Fbtrfs-progs.git btrfs-progs: image: use fixed-size array for worker thread pointers No need to dynamically allocate the thread pointers. Signed-off-by: David Sterba --- diff --git a/btrfs-image.c b/btrfs-image.c index 3f40301..e54e3fc 100644 --- a/btrfs-image.c +++ b/btrfs-image.c @@ -99,7 +99,7 @@ struct metadump_struct { struct meta_cluster *cluster; - pthread_t *threads; + pthread_t threads[MAX_WORKER_THREADS]; size_t num_threads; pthread_mutex_t mutex; pthread_cond_t cond; @@ -132,7 +132,7 @@ struct mdrestore_struct { FILE *in; FILE *out; - pthread_t *threads; + pthread_t threads[MAX_WORKER_THREADS]; size_t num_threads; pthread_mutex_t mutex; pthread_cond_t cond; @@ -738,7 +738,6 @@ static void metadump_destroy(struct metadump_struct *md, int num_threads) free(name->sub); free(name); } - free(md->threads); free(md->cluster); } @@ -752,11 +751,6 @@ static int metadump_init(struct metadump_struct *md, struct btrfs_root *root, md->cluster = calloc(1, BLOCK_SIZE); if (!md->cluster) return -ENOMEM; - md->threads = calloc(num_threads, sizeof(pthread_t)); - if (!md->threads) { - free(md->cluster); - return -ENOMEM; - } INIT_LIST_HEAD(&md->list); INIT_LIST_HEAD(&md->ordered); md->root = root; @@ -1841,7 +1835,6 @@ static void mdrestore_destroy(struct mdrestore_struct *mdres, int num_threads) pthread_cond_destroy(&mdres->cond); pthread_mutex_destroy(&mdres->mutex); - free(mdres->threads); } static int mdrestore_init(struct mdrestore_struct *mdres, @@ -1871,11 +1864,8 @@ static int mdrestore_init(struct mdrestore_struct *mdres, return 0; mdres->num_threads = num_threads; - mdres->threads = calloc(num_threads, sizeof(pthread_t)); - if (!mdres->threads) - return -ENOMEM; for (i = 0; i < num_threads; i++) { - ret = pthread_create(mdres->threads + i, NULL, restore_worker, + ret = pthread_create(&mdres->threads[i], NULL, restore_worker, mdres); if (ret) { /* pthread_create returns errno directly */