diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-04-26 20:35:17 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-04-26 20:35:17 +0200 |
commit | 46a7bdce1581ac23105c61567b47affe4867e92d (patch) | |
tree | 63185a7ae44c6cb29010baace9e8f61f1281c97a /src/libmdsserver/fd-table.c | |
parent | add table optimised for file descriptors (diff) | |
download | mds-46a7bdce1581ac23105c61567b47affe4867e92d.tar.gz mds-46a7bdce1581ac23105c61567b47affe4867e92d.tar.bz2 mds-46a7bdce1581ac23105c61567b47affe4867e92d.tar.xz |
take care of realloc failures
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/libmdsserver/fd-table.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/libmdsserver/fd-table.c b/src/libmdsserver/fd-table.c index 0b11f5d..64f0b99 100644 --- a/src/libmdsserver/fd-table.c +++ b/src/libmdsserver/fd-table.c @@ -174,10 +174,14 @@ size_t fd_table_put(fd_table_t* restrict this, int key, size_t value) errno = 0; if ((size_t)key >= this->capacity) { + size_t* old_values = this->values; size_t old_bitcap, new_bitcap; this->values = realloc(this->values, (this->capacity << 1) * sizeof(size_t)); if (this->values == NULL) - return 0; + { + this->values = old_values; + return 0; + } memset(this->values + this->capacity, 0, this->capacity * sizeof(size_t)); @@ -187,9 +191,14 @@ size_t fd_table_put(fd_table_t* restrict this, int key, size_t value) if (new_bitcap > old_bitcap) { + uint64_t* old_used = this->used; this->used = realloc(this->used, new_bitcap * sizeof(size_t)); if (this->used == NULL) - return 0; + { + this->used = old_used; + this->capacity >>= 1; + return 0; + } memset(this->used + old_bitcap, 0, (new_bitcap - old_bitcap) * sizeof(uint64_t)); } |