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

@@ -110,10 +110,9 @@ void *agent_pool(void *args)
struct pool_data *pool = args;
pthread_mutex_t mutex;
pthread_attr_t attr;
pthread_t *agent_thread =
(pthread_t *)malloc(pool->size * sizeof(pthread_t));
pthread_t *agent_thread = malloc(pool->size * sizeof(*agent_thread));
struct agent_args *agent_struct =
malloc(pool->size * sizeof(struct agent_args));
malloc(pool->size * sizeof(*agent_struct));
int i;
memset(agent_thread, 0, sizeof(pthread_t) * pool->size);