diff options
author | Mattias Andrée <maandree@kth.se> | 2022-03-20 08:30:40 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2022-03-20 08:30:40 +0100 |
commit | f3a7696b190f58379c81bcf8683b86373eedfc63 (patch) | |
tree | a9ac6b5aba89551f62cfcac15ca83247d95a61d7 /libar2simplified_init_context.c | |
parent | Fix linking for Mac OS (diff) | |
download | libar2simplified-f3a7696b190f58379c81bcf8683b86373eedfc63.tar.gz libar2simplified-f3a7696b190f58379c81bcf8683b86373eedfc63.tar.bz2 libar2simplified-f3a7696b190f58379c81bcf8683b86373eedfc63.tar.xz |
Fix allocation success check and deallocation order1.1.1
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libar2simplified_init_context.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/libar2simplified_init_context.c b/libar2simplified_init_context.c index c7f8b69..9dcbfb0 100644 --- a/libar2simplified_init_context.c +++ b/libar2simplified_init_context.c @@ -155,9 +155,9 @@ destroy_thread_pool(struct libar2_context *ctx) if (data->threads[i].error) ret = data->threads[i].error; } - free(data->threads); sem_destroy(&data->semaphore); pthread_mutex_destroy(&data->mutex); + free(data->threads); free(data); return ret; } @@ -216,6 +216,10 @@ init_thread_pool(size_t desired, size_t *createdp, struct libar2_context *ctx) size = (desired + 63) / 64; size *= sizeof(uint_least64_t) * 2; data = alignedalloc(1, offsetof(struct user_data, resting), size, ALIGNOF(struct user_data)); + if (!data) { + errno = ENOMEM; + return -1; + } memset(data, 0, offsetof(struct user_data, resting) + size); data->joined = &data->resting[(desired + 63) / 64]; ctx->user_data = data; |