diff options
author | dreamer.dead <dreamer.dead@gmail.com> | 2020-07-24 07:20:31 +0000 |
---|---|---|
committer | dreamer.dead <dreamer.dead@gmail.com> | 2020-07-24 07:20:31 +0000 |
commit | 85dbfbaedecb46ebd0aa89ffeb674de497555ca9 (patch) | |
tree | 3c13af26923c64ea4b9dec87e1dbc93e5b01fd4b | |
parent | d9d5e44526a3b8065e4ae913032020d0bfd93103 (diff) |
Use unique_ptr to prevent memory leaks in VideoDevice class
-rw-r--r-- | kms++util/inc/kms++util/videodevice.h | 5 | ||||
-rw-r--r-- | kms++util/src/videodevice.cpp | 10 |
2 files changed, 8 insertions, 7 deletions
diff --git a/kms++util/inc/kms++util/videodevice.h b/kms++util/inc/kms++util/videodevice.h index e089bcd..0aaa103 100644 --- a/kms++util/inc/kms++util/videodevice.h +++ b/kms++util/inc/kms++util/videodevice.h @@ -1,6 +1,7 @@ #pragma once #include <string> +#include <memory> #include <kms++/kms++.h> class VideoStreamer; @@ -50,8 +51,8 @@ private: std::vector<kms::DumbFramebuffer*> m_capture_fbs; std::vector<kms::DumbFramebuffer*> m_output_fbs; - VideoStreamer* m_capture_streamer; - VideoStreamer* m_output_streamer; + std::unique_ptr<VideoStreamer> m_capture_streamer; + std::unique_ptr<VideoStreamer> m_output_streamer; }; class VideoStreamer diff --git a/kms++util/src/videodevice.cpp b/kms++util/src/videodevice.cpp index 89a7286..0121c7c 100644 --- a/kms++util/src/videodevice.cpp +++ b/kms++util/src/videodevice.cpp @@ -246,7 +246,7 @@ VideoDevice::VideoDevice(const string& dev) } VideoDevice::VideoDevice(int fd) - : m_fd(fd), m_has_capture(false), m_has_output(false), m_has_m2m(false), m_capture_streamer(0), m_output_streamer(0) + : m_fd(fd), m_has_capture(false), m_has_output(false), m_has_m2m(false) { if (fd < 0) throw runtime_error("bad fd"); @@ -299,10 +299,10 @@ VideoStreamer* VideoDevice::get_capture_streamer() if (!m_capture_streamer) { auto type = m_has_mplane_capture ? VideoStreamer::StreamerType::CaptureMulti : VideoStreamer::StreamerType::CaptureSingle; - m_capture_streamer = new VideoStreamer(m_fd, type); + m_capture_streamer = std::unique_ptr<VideoStreamer>(new VideoStreamer(m_fd, type)); } - return m_capture_streamer; + return m_capture_streamer.get(); } VideoStreamer* VideoDevice::get_output_streamer() @@ -311,10 +311,10 @@ VideoStreamer* VideoDevice::get_output_streamer() if (!m_output_streamer) { auto type = m_has_mplane_output ? VideoStreamer::StreamerType::OutputMulti : VideoStreamer::StreamerType::OutputSingle; - m_output_streamer = new VideoStreamer(m_fd, type); + m_output_streamer = std::unique_ptr<VideoStreamer>(new VideoStreamer(m_fd, type)); } - return m_output_streamer; + return m_output_streamer.get(); } vector<tuple<uint32_t, uint32_t>> VideoDevice::get_discrete_frame_sizes(PixelFormat fmt) |