Make allocations based on var size, not struct size - it's safer

This commit is contained in:
2017-06-21 12:20:47 +03:00
parent a0915fc803
commit bee649a34e
4 changed files with 8 additions and 9 deletions

View File

@@ -85,9 +85,9 @@ void *client_pool(void *args)
struct pool_data *pool = args;
pthread_mutex_t mutex;
pthread_attr_t attr;
pthread_t *client_thread = (pthread_t *)malloc(pool->size * sizeof(pthread_t));
pthread_t *client_thread = malloc(pool->size * sizeof(*client_thread));
struct client_args *client_struct =
(struct client_args *)malloc(pool->size * sizeof(struct client_args));
malloc(pool->size * sizeof(*client_struct));
int i;
memset(client_thread, 0, sizeof(pthread_t) * pool->size);