diff options
author | jstebbins <[email protected]> | 2011-11-15 22:56:19 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2011-11-15 22:56:19 +0000 |
commit | 6456852b5317e555c66101ef3a2582afb3ad06bc (patch) | |
tree | 5f27d50cc2c260564fccbd5ce3e5e81cd3b8ed88 /libhb | |
parent | 935fe113ea0008656f4dfec80be731fd6d6c25d1 (diff) |
Fix out of memory condition on mingw32
realloc doesn't really release memory under most circumstances, so it's
not suitable for reducing the size of an hb_buffer_t. So instead,
allocate a new smaller buffer, copy the data, and return the old larger
buffer to the buffer pool for reuse.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4353 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/fifo.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/libhb/fifo.c b/libhb/fifo.c index 7b5660673..cb2b4b6ce 100644 --- a/libhb/fifo.c +++ b/libhb/fifo.c @@ -200,14 +200,11 @@ void hb_buffer_reduce( hb_buffer_t * b, int size ) { if ( size < b->alloc / 8 || b->data == NULL ) { - uint32_t orig = b->alloc; - size = size_to_pool( size )->buffer_size; - b->data = realloc( b->data, size ); - b->alloc = size; + hb_buffer_t * tmp = hb_buffer_init( size ); - hb_lock(buffers.lock); - buffers.allocated += size - orig; - hb_unlock(buffers.lock); + hb_buffer_swap_copy( b, tmp ); + memcpy( b->data, tmp->data, size ); + hb_buffer_close( &tmp ); } } |