diff options
author | Erik de Castro Lopo <erikd@mega-nerd.com> | 2015-08-22 19:22:50 +1000 |
---|---|---|
committer | Erik de Castro Lopo <erikd@mega-nerd.com> | 2015-08-22 19:39:37 +1000 |
commit | d9ae5e9128f13fb43d33adf732c313516c70f9c6 (patch) | |
tree | 26a45432c984de73f845b4a23848c65d3e81b18f /src/libFLAC/format.c | |
parent | 684fb3d544b6fec54464e2f09296eb8d7705382a (diff) | |
download | flac-d9ae5e9128f13fb43d33adf732c313516c70f9c6.tar.gz |
libFLAC: Add function safe_realloc_()
The new function wraps, realloc() and if the realloc() fails, it
free()s the old pointer.
This is an improvement on the potential realloc() memory leak that
was fixed in 15a9062609.
Still needs fuzzing to validate it.
Diffstat (limited to 'src/libFLAC/format.c')
-rw-r--r-- | src/libFLAC/format.c | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/src/libFLAC/format.c b/src/libFLAC/format.c index 5215c56a..0f601afb 100644 --- a/src/libFLAC/format.c +++ b/src/libFLAC/format.c @@ -39,6 +39,7 @@ #include <string.h> /* for memset() */ #include "FLAC/assert.h" #include "FLAC/format.h" +#include "share/alloc.h" #include "share/compat.h" #include "private/format.h" #include "private/macros.h" @@ -573,17 +574,10 @@ FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_s FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits)); if(object->capacity_by_order < max_partition_order) { - void *oldptr; - oldptr = object->parameters; - if(0 == (object->parameters = realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order)))) { - free(oldptr); + if(0 == (object->parameters = safe_realloc_(object->parameters, sizeof(unsigned)*(1 << max_partition_order)))) return false; - } - oldptr = object->raw_bits; - if(0 == (object->raw_bits = realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order)))) { - free(oldptr); + if(0 == (object->raw_bits = safe_realloc_(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order)))) return false; - } memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order)); object->capacity_by_order = max_partition_order; } |