summaryrefslogtreecommitdiffstats
path: root/libhb/fifo.c
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2014-10-30 18:35:25 +0000
committerjstebbins <[email protected]>2014-10-30 18:35:25 +0000
commit7fd3494667e29925340f9fc5c48a4c6ae0ef76bb (patch)
tree21735c396c62333a44f8430e061ce6f9a45fc33e /libhb/fifo.c
parent6c82462e74f0d6556827f5bfaa56d80527f7baa6 (diff)
fifo: add code (ifdef'd out) to assist with finding buffer leaks
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6485 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/fifo.c')
-rw-r--r--libhb/fifo.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/libhb/fifo.c b/libhb/fifo.c
index 0e05ea031..5e24adc2a 100644
--- a/libhb/fifo.c
+++ b/libhb/fifo.c
@@ -16,6 +16,7 @@
#define FIFO_TIMEOUT 200
//#define HB_FIFO_DEBUG 1
+//#define HB_BUFFER_DEBUG 1
/* Fifo */
struct hb_fifo_s
@@ -64,6 +65,9 @@ struct hb_buffer_pools_s
int64_t allocated;
hb_lock_t *lock;
hb_fifo_t *pool[MAX_BUFFER_POOLS];
+#if defined(HB_BUFFER_DEBUG)
+ hb_list_t *alloc_list;
+#endif
} buffers;
@@ -72,6 +76,10 @@ void hb_buffer_pool_init( void )
buffers.lock = hb_lock_init();
buffers.allocated = 0;
+#if defined(HB_BUFFER_DEBUG)
+ buffers.alloc_list = hb_list_init();
+#endif
+
/* we allocate pools for sizes 2^10 through 2^25. requests larger than
* 2^25 will get passed through to malloc. */
int i;
@@ -243,6 +251,16 @@ void hb_buffer_pool_free( void )
hb_lock(buffers.lock);
+#if defined(HB_BUFFER_DEBUG)
+ hb_deep_log(2, "leaked %d buffers", hb_list_count(buffers.alloc_list));
+ for (i = 0; i < hb_list_count(buffers.alloc_list); i++)
+ {
+ hb_buffer_t *b = hb_list_item(buffers.alloc_list, i);
+ hb_deep_log(2, "leaked buffer %p type %d size %d alloc %d",
+ b, b->s.type, b->size, b->alloc);
+ }
+#endif
+
for( i = BUFFER_POOL_FIRST; i <= BUFFER_POOL_LAST; ++i)
{
count = 0;
@@ -350,6 +368,11 @@ hb_buffer_t * hb_buffer_init_internal( int size , int needsMapped )
b->cl.last_event = last_event;
b->cl.buffer_location = loc;
+#if defined(HB_BUFFER_DEBUG)
+ hb_lock(buffers.lock);
+ hb_list_add(buffers.alloc_list, b);
+ hb_unlock(buffers.lock);
+#endif
return( b );
}
}
@@ -410,6 +433,11 @@ hb_buffer_t * hb_buffer_init_internal( int size , int needsMapped )
b->s.start = AV_NOPTS_VALUE;
b->s.stop = AV_NOPTS_VALUE;
b->s.renderOffset = AV_NOPTS_VALUE;
+#if defined(HB_BUFFER_DEBUG)
+ hb_lock(buffers.lock);
+ hb_list_add(buffers.alloc_list, b);
+ hb_unlock(buffers.lock);
+#endif
return b;
}
@@ -632,6 +660,11 @@ void hb_buffer_close( hb_buffer_t ** _b )
b->next = NULL;
+#if defined(HB_BUFFER_DEBUG)
+ hb_lock(buffers.lock);
+ hb_list_rem(buffers.alloc_list, b);
+ hb_unlock(buffers.lock);
+#endif
// Close any attached subtitle buffers
hb_buffer_close( &b->sub );