diff options
author | Richard Mudgett <rmudgett@digium.com> | 2013-09-10 18:05:47 +0000 |
---|---|---|
committer | Richard Mudgett <rmudgett@digium.com> | 2013-09-10 18:05:47 +0000 |
commit | 83bf017db9804c9274608ded72d70a72c086d756 (patch) | |
tree | a2f9a38495c75235101c86a3572529098fc5800f /main/heap.c | |
parent | 87cf916cdbcf16d244bd71d91ec5b849cc186923 (diff) |
Fix incorrect usages of ast_realloc().
There are several locations in the code base where this is done:
buf = ast_realloc(buf, new_size);
This is going to leak the original buf contents if the realloc fails.
Review: https://reviewboard.asterisk.org/r/2832/
........
Merged revisions 398757 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 398758 from http://svn.asterisk.org/svn/asterisk/branches/11
........
Merged revisions 398759 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@398760 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/heap.c')
-rw-r--r-- | main/heap.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/main/heap.c b/main/heap.c index b2c0d3835..c04f7a010 100644 --- a/main/heap.c +++ b/main/heap.c @@ -181,18 +181,19 @@ static int grow_heap(struct ast_heap *h #endif ) { - h->avail_len = h->avail_len * 2 + 1; + void **new_heap; + size_t new_len = h->avail_len * 2 + 1; - if (!(h->heap = #ifdef MALLOC_DEBUG - __ast_realloc(h->heap, h->avail_len * sizeof(void *), file, lineno, func) + new_heap = __ast_realloc(h->heap, new_len * sizeof(void *), file, lineno, func); #else - ast_realloc(h->heap, h->avail_len * sizeof(void *)) + new_heap = ast_realloc(h->heap, new_len * sizeof(void *)); #endif - )) { - h->cur_len = h->avail_len = 0; + if (!new_heap) { return -1; } + h->heap = new_heap; + h->avail_len = new_len; return 0; } |