summaryrefslogtreecommitdiffstats
path: root/encoder.cc
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 09:30:45 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 09:30:45 +0000
commit4a9d4aa2993742892cbc608b9df295e7c43a9b89 (patch)
treee6127869ff2cf3fa12b493926c84c4aec34a626e /encoder.cc
parentAdding upstream version 1.12. (diff)
downloadlzip-4a9d4aa2993742892cbc608b9df295e7c43a9b89.tar.xz
lzip-4a9d4aa2993742892cbc608b9df295e7c43a9b89.zip
Adding upstream version 1.13~rc1.upstream/1.13_rc1
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'encoder.cc')
-rw-r--r--encoder.cc12
1 files changed, 8 insertions, 4 deletions
diff --git a/encoder.cc b/encoder.cc
index 1bdf78e..79dd5cf 100644
--- a/encoder.cc
+++ b/encoder.cc
@@ -63,12 +63,14 @@ Matchfinder::Matchfinder( const int dict_size, const int len_limit,
const int buffer_size_limit = ( 2 * dict_size ) + before_size + after_size;
buffer_size = std::max( 65536, dict_size );
buffer = (uint8_t *)std::malloc( buffer_size );
- if( !buffer ) throw std::bad_alloc();
+ if( !buffer ) { delete[] prev_positions; throw std::bad_alloc(); }
if( read_block() && !at_stream_end && buffer_size < buffer_size_limit )
{
buffer_size = buffer_size_limit;
- buffer = (uint8_t *)std::realloc( buffer, buffer_size );
- if( !buffer ) throw std::bad_alloc();
+ uint8_t * const tmp = (uint8_t *)std::realloc( buffer, buffer_size );
+ if( !tmp )
+ { std::free( buffer ); delete[] prev_positions; throw std::bad_alloc(); }
+ buffer = tmp;
read_block();
}
if( at_stream_end && stream_pos < dict_size )
@@ -76,7 +78,9 @@ Matchfinder::Matchfinder( const int dict_size, const int len_limit,
else dictionary_size_ = dict_size;
pos_limit = buffer_size;
if( !at_stream_end ) pos_limit -= after_size;
- prev_pos_tree = new int32_t[2*dictionary_size_];
+ prev_pos_tree = new( std::nothrow ) int32_t[2*dictionary_size_];
+ if( !prev_pos_tree )
+ { std::free( buffer ); delete[] prev_positions; throw std::bad_alloc(); }
for( int i = 0; i < num_prev_positions; ++i ) prev_positions[i] = -1;
}