From: Steinar H. Gunderson Date: Mon, 2 May 2016 23:50:17 +0000 (+0200) Subject: Stop leaking memory allocators in DeckLinkCapture. X-Git-Tag: 1.3.0~31 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=add2055b0dbc8a6f6cda986a41481ca0061c1e05;hp=d836455bb8b4383f7f3f6f3c037bd72691d94e20;p=nageru Stop leaking memory allocators in DeckLinkCapture. --- diff --git a/decklink_capture.cpp b/decklink_capture.cpp index a4753cb..2519caa 100644 --- a/decklink_capture.cpp +++ b/decklink_capture.cpp @@ -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()); } } diff --git a/decklink_capture.h b/decklink_capture.h index f547116..59c3b02 100644 --- a/decklink_capture.h +++ b/decklink_capture.h @@ -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 owned_video_frame_allocator; + std::unique_ptr owned_audio_frame_allocator; frame_callback_t frame_callback = nullptr; IDeckLinkConfiguration *config = nullptr;