diff options
author | Rikard Falkeborn <rikard.falkeborn@gmail.com> | 2015-08-10 21:42:38 +0200 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2015-10-21 15:11:27 +1000 |
commit | aa8a674b6b2c8474a1111b16806c27d4562b5d80 (patch) | |
tree | d4cb9d4e6da4c4d02974dd0c96ad16230241fea7 /src | |
parent | 19d373c9b95ff5c9ee6d5a4cdb097670f69068d4 (diff) | |
download | pacman-aa8a674b6b2c8474a1111b16806c27d4562b5d80.tar.xz |
pacsort: don't overwrite memory if realloc fails
That makes it impossible to free it later.
Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/util/pacsort.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/util/pacsort.c b/src/util/pacsort.c index 003ec073..3337d976 100644 --- a/src/util/pacsort.c +++ b/src/util/pacsort.c @@ -104,10 +104,11 @@ static void buffer_free(struct buffer_t *buf) static int buffer_grow(struct buffer_t *buffer) { size_t newsz = buffer->maxlen * 2.5; - buffer->mem = realloc(buffer->mem, newsz * sizeof(char)); - if(!buffer->mem) { + char* new_mem = realloc(buffer->mem, newsz * sizeof(char)); + if(!new_mem) { return 1; } + buffer->mem = new_mem; buffer->maxlen = newsz; return 0; @@ -136,11 +137,12 @@ static struct list_t *list_new(size_t initial_size) static int list_grow(struct list_t *list) { size_t newsz = list->maxcount * 2.5; - list->list = realloc(list->list, newsz * sizeof(char *)); - if(!list->list) { + void **new_list = realloc(list->list, newsz * sizeof(char *)); + if(!new_list) { return 1; } + list->list = new_list; list->maxcount = newsz; return 0; |