]> git.sesse.net Git - bmusb/blobdiff - bmusb.h
Stop leaking memory allocators.
[bmusb] / bmusb.h
diff --git a/bmusb.h b/bmusb.h
index 9ee6617a6e7874164a8a53603a47d974acf01694..4c7254bcb5dea6bb773381c510565cea37035839 100644 (file)
--- a/bmusb.h
+++ b/bmusb.h
@@ -177,6 +177,9 @@ class BMUSBCapture : public CaptureInterface {
        void set_video_frame_allocator(FrameAllocator *allocator) override
        {
                video_frame_allocator = allocator;
+               if (owned_video_frame_allocator.get() != allocator) {
+                       owned_video_frame_allocator.reset();
+               }
        }
 
        FrameAllocator *get_video_frame_allocator() override
@@ -188,6 +191,9 @@ class BMUSBCapture : public CaptureInterface {
        void set_audio_frame_allocator(FrameAllocator *allocator) override
        {
                audio_frame_allocator = allocator;
+               if (owned_audio_frame_allocator.get() != allocator) {
+                       owned_audio_frame_allocator.reset();
+               }
        }
 
        FrameAllocator *get_audio_frame_allocator() override
@@ -251,6 +257,8 @@ class BMUSBCapture : public CaptureInterface {
 
        FrameAllocator *video_frame_allocator = nullptr;
        FrameAllocator *audio_frame_allocator = nullptr;
+       std::unique_ptr<FrameAllocator> owned_video_frame_allocator;
+       std::unique_ptr<FrameAllocator> owned_audio_frame_allocator;
        frame_callback_t frame_callback = nullptr;
 
        std::thread dequeue_thread;