]> git.sesse.net Git - nageru/commitdiff
Stop leaking memory allocators in DeckLinkCapture.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 2 May 2016 23:50:17 +0000 (01:50 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 2 May 2016 23:59:32 +0000 (01:59 +0200)
decklink_capture.cpp
decklink_capture.h

index a4753cbd767eefc8a480242a64775cedf95c3141..2519caa5ef05034b7ef136d6d769f50b10ba2aca 100644 (file)
@@ -384,10 +384,12 @@ HRESULT STDMETHODCALLTYPE DeckLinkCapture::VideoInputFrameArrived(
 void DeckLinkCapture::configure_card()
 {
        if (video_frame_allocator == nullptr) {
-               set_video_frame_allocator(new MallocFrameAllocator(FRAME_SIZE, NUM_QUEUED_VIDEO_FRAMES));  // FIXME: leak.
+               owned_video_frame_allocator.reset(new MallocFrameAllocator(FRAME_SIZE, NUM_QUEUED_VIDEO_FRAMES));
+               set_video_frame_allocator(owned_video_frame_allocator.get());
        }
        if (audio_frame_allocator == nullptr) {
-               set_audio_frame_allocator(new MallocFrameAllocator(65536, NUM_QUEUED_AUDIO_FRAMES));  // FIXME: leak.
+               owned_audio_frame_allocator.reset(new MallocFrameAllocator(65536, NUM_QUEUED_AUDIO_FRAMES));
+               set_audio_frame_allocator(owned_audio_frame_allocator.get());
        }
 }
 
index f54711674b73757851f14c20c3e5f00fcff8f057..59c3b02e6096528098e315a64d98034ecfa1b2cf 100644 (file)
@@ -36,6 +36,9 @@ public:
        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
@@ -47,6 +50,9 @@ public:
        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
@@ -102,6 +108,8 @@ private:
 
        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;
 
        IDeckLinkConfiguration *config = nullptr;