Skip to content

Commit

Permalink
added checking for null pointer in new_Assoc function
Browse files Browse the repository at this point in the history
  • Loading branch information
lobiCode committed Aug 29, 2014
1 parent f1ed0ee commit 52ad2c6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions toxcore/assoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down

0 comments on commit 52ad2c6

Please sign in to comment.