diff options
author | John Stebbins <[email protected]> | 2016-05-11 09:30:45 -0700 |
---|---|---|
committer | John Stebbins <[email protected]> | 2016-05-17 10:09:29 -0600 |
commit | e3815957e8a6be2a06a526cac803340f9b6ad1b6 (patch) | |
tree | 56d15e2ff5e7c9184f5a8d28477c18494ac7be23 | |
parent | fd0c4626a9eb9074ee3e426ce48256a52b2f7362 (diff) |
buffers: add more buffer allocation debugging
-rw-r--r-- | libhb/fifo.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/libhb/fifo.c b/libhb/fifo.c index beba27102..0795619ce 100644 --- a/libhb/fifo.c +++ b/libhb/fifo.c @@ -25,6 +25,10 @@ //#define HB_BUFFER_DEBUG 1 //#define HB_NO_BUFFER_POOL 1 +#if defined(HB_BUFFER_DEBUG) +#include <assert.h> +#endif + /* Fifo */ struct hb_fifo_s { @@ -81,6 +85,10 @@ struct hb_buffer_pools_s } buffers; +#if defined(HB_BUFFER_DEBUG) +static int hb_fifo_contains( hb_fifo_t *f, hb_buffer_t *b ); +#endif + void hb_buffer_pool_init( void ) { buffers.lock = hb_lock_init(); @@ -746,6 +754,13 @@ void hb_buffer_close( hb_buffer_t ** _b ) #endif if( buffer_pool && b->data && !hb_fifo_is_full( buffer_pool ) ) { +#if defined(HB_BUFFER_DEBUG) + if (hb_fifo_contains(buffer_pool, b)) + { + hb_error("hb_buffer_close: buffer %p already freed", b); + assert(0); + } +#endif hb_fifo_push_head( buffer_pool, b ); b = next; continue; @@ -1261,3 +1276,19 @@ void hb_fifo_flush( hb_fifo_t * f ) } +#if defined(HB_BUFFER_DEBUG) +static int hb_fifo_contains( hb_fifo_t *f, hb_buffer_t *b ) +{ + hb_buffer_t * tmp = f->first; + + while (tmp != NULL) + { + if (b == tmp) + { + return 1; + } + tmp = tmp->next; + } + return 0; +} +#endif |