]> git.sesse.net Git - mlt/commitdiff
fix memory leak when using mlt_cache for frames
authorDan Dennedy <dan@dennedy.org>
Sat, 4 Aug 2012 00:09:41 +0000 (17:09 -0700)
committerDan Dennedy <dan@dennedy.org>
Sun, 5 Aug 2012 04:08:10 +0000 (21:08 -0700)
src/framework/mlt_cache.c

index 903ec59c488d5868cfebb0b8773e270552198c3b..9efa0a1301f52b4a81754ab8d301ebdcaddc785f 100644 (file)
@@ -83,6 +83,7 @@ struct mlt_cache_s
 {
        int count;             /**< the number of items currently in the cache */
        int size;              /**< the maximum number of items permitted in the cache <= \p MAX_CACHE_SIZE */
+       int is_frames;         /**< indicates if this cache is used to cache frames */
        void* *current;        /**< pointer to the current array of pointers */
        void* A[ MAX_CACHE_SIZE ];
        void* B[ MAX_CACHE_SIZE ];
@@ -122,6 +123,13 @@ static void cache_object_close( mlt_cache cache, void *object, void* data )
 {
        char key[19];
 
+       if ( cache->is_frames )
+       {
+               // Frame caches are easy - just close the object as mlt_frame.
+               mlt_frame_close( object );
+               return;
+       }
+
        // Fetch the cache item from the active list by its owner's address
        sprintf( key, "%p", object );
        mlt_cache_item item = mlt_properties_get_data( cache->active, key, NULL );
@@ -557,6 +565,7 @@ void mlt_cache_put_frame( mlt_cache cache, mlt_frame frame )
 
        // swap the current array
        cache->current = (void**) alt;
+       cache->is_frames = 1;
        pthread_mutex_unlock( &cache->mutex );
 }