From 52ad2c64f71ff185bb5418fd23c53f5d82627fd7 Mon Sep 17 00:00:00 2001 From: slaniCode Date: Fri, 29 Aug 2014 15:21:19 +0200 Subject: [PATCH] added checking for null pointer in new_Assoc function --- toxcore/assoc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/toxcore/assoc.c b/toxcore/assoc.c index 4d837aa3..417b6139 100644 --- a/toxcore/assoc.c +++ b/toxcore/assoc.c @@ -831,8 +831,20 @@ Assoc *new_Assoc(size_t bits, size_t entries, const uint8_t *public_id) /* allocation: preferably few blobs */ size_t bckt, cix; Client_entry *clients = malloc(sizeof(*clients) * assoc->candidates_bucket_count * assoc->candidates_bucket_size); + + if (!clients) { + free(assoc); + return NULL; + } + candidates_bucket *lists = malloc(sizeof(*lists) * assoc->candidates_bucket_count); + if (!lists) { + free(assoc); + free(clients); + return NULL; + } + for (bckt = 0; bckt < assoc->candidates_bucket_count; bckt++) { candidates_bucket *list = &lists[bckt];