From: Carl Hetherington Date: Sun, 19 Dec 2021 23:35:11 +0000 (+0100) Subject: Fix a load of stuff that wasn't being freed on close. X-Git-Tag: checked-for-v2.16.x~130 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=a7f61a15fc974feaff1554bd5322650676a63c51 Fix a load of stuff that wasn't being freed on close. Nothing really that important, but it cleans up the valgrind leak check reports. --- diff --git a/src/lib/audio_processor.cc b/src/lib/audio_processor.cc index 1eb796b38..6f3b96145 100644 --- a/src/lib/audio_processor.cc +++ b/src/lib/audio_processor.cc @@ -27,31 +27,36 @@ using std::string; -using std::list; +using std::unique_ptr; +using std::vector; -list AudioProcessor::_all; -list AudioProcessor::_non_experimental; +vector> AudioProcessor::_experimental; +vector> AudioProcessor::_non_experimental; void AudioProcessor::setup_audio_processors () { - auto mid_side = new MidSideDecoder (); - _all.push_back (mid_side); - _non_experimental.push_back (mid_side); + _non_experimental.push_back (unique_ptr(new MidSideDecoder())); - _all.push_back (new UpmixerA(48000)); - _all.push_back (new UpmixerB(48000)); + _experimental.push_back (unique_ptr(new UpmixerA(48000))); + _experimental.push_back (unique_ptr(new UpmixerB(48000))); } AudioProcessor const * AudioProcessor::from_id (string id) { - for (auto i: _all) { + for (auto& i: _non_experimental) { if (i->id() == id) { - return i; + return i.get(); + } + } + + for (auto& i: _experimental) { + if (i->id() == id) { + return i.get(); } } @@ -59,19 +64,35 @@ AudioProcessor::from_id (string id) } -list +vector AudioProcessor::visible () { + vector raw; if (Config::instance()->show_experimental_audio_processors()) { - return _all; + for (auto& processor: _experimental) { + raw.push_back (processor.get()); + } } - return _non_experimental; + for (auto& processor: _non_experimental) { + raw.push_back (processor.get()); + } + + return raw; } -list +vector AudioProcessor::all () { - return _all; + vector raw; + for (auto& processor: _experimental) { + raw.push_back (processor.get()); + } + + for (auto& processor: _non_experimental) { + raw.push_back (processor.get()); + } + + return raw; } diff --git a/src/lib/audio_processor.h b/src/lib/audio_processor.h index ca80c92b2..e24506acd 100644 --- a/src/lib/audio_processor.h +++ b/src/lib/audio_processor.h @@ -29,7 +29,7 @@ #include "types.h" -#include +#include #include #include @@ -65,14 +65,14 @@ public: /** @return the user-visible (translated) names of each of our inputs, in order */ virtual std::vector input_names () const = 0; - static std::list all (); - static std::list visible (); + static std::vector all (); + static std::vector visible (); static void setup_audio_processors (); static AudioProcessor const * from_id (std::string); private: - static std::list _all; - static std::list _non_experimental; + static std::vector> _experimental; + static std::vector> _non_experimental; }; diff --git a/src/lib/cinema_sound_processor.cc b/src/lib/cinema_sound_processor.cc index 1eaf8e1fc..434fdd1cf 100644 --- a/src/lib/cinema_sound_processor.cc +++ b/src/lib/cinema_sound_processor.cc @@ -36,7 +36,7 @@ using namespace std; -vector CinemaSoundProcessor::_cinema_sound_processors; +vector> CinemaSoundProcessor::_cinema_sound_processors; /** @param i Our id. @@ -57,7 +57,11 @@ CinemaSoundProcessor::CinemaSoundProcessor (string i, string n, float knee, floa vector CinemaSoundProcessor::all () { - return _cinema_sound_processors; + vector raw; + for (auto& processor: _cinema_sound_processors) { + raw.push_back (processor.get()); + } + return raw; } @@ -67,9 +71,9 @@ CinemaSoundProcessor::all () void CinemaSoundProcessor::setup_cinema_sound_processors () { - _cinema_sound_processors.push_back (new DolbyCP750); - _cinema_sound_processors.push_back (new USL); - _cinema_sound_processors.push_back (new DatasatAP2x); + _cinema_sound_processors.push_back (unique_ptr(new DolbyCP750)); + _cinema_sound_processors.push_back (unique_ptr(new USL)); + _cinema_sound_processors.push_back (unique_ptr(new DatasatAP2x)); } @@ -88,26 +92,7 @@ CinemaSoundProcessor::from_id (string id) return nullptr; } - return *i; -} - - -/** @param s A sound processor from our static list. - * @return Index of the sound processor with the list, or -1. - */ -int -CinemaSoundProcessor::as_index (CinemaSoundProcessor const * s) -{ - vector::size_type i = 0; - while (i < _cinema_sound_processors.size() && _cinema_sound_processors[i] != s) { - ++i; - } - - if (i == _cinema_sound_processors.size ()) { - return -1; - } - - return i; + return i->get(); } @@ -118,7 +103,7 @@ CinemaSoundProcessor const * CinemaSoundProcessor::from_index (int i) { DCPOMATIC_ASSERT (i >= 0 && i < int(_cinema_sound_processors.size())); - return _cinema_sound_processors[i]; + return _cinema_sound_processors[i].get(); } diff --git a/src/lib/cinema_sound_processor.h b/src/lib/cinema_sound_processor.h index ef003da2a..3ccaa5c9b 100644 --- a/src/lib/cinema_sound_processor.h +++ b/src/lib/cinema_sound_processor.h @@ -29,6 +29,7 @@ #include +#include #include #include @@ -64,7 +65,6 @@ public: static void setup_cinema_sound_processors (); static CinemaSoundProcessor const * from_id (std::string id); static CinemaSoundProcessor const * from_index (int); - static int as_index (CinemaSoundProcessor const *); private: /** id for our use */ @@ -75,8 +75,8 @@ private: float _below; float _above; - /** sll available cinema sound processors */ - static std::vector _cinema_sound_processors; + /** all available cinema sound processors */ + static std::vector> _cinema_sound_processors; }; diff --git a/src/lib/dcp_content_type.cc b/src/lib/dcp_content_type.cc index 6d7286a48..f3cd02e9f 100644 --- a/src/lib/dcp_content_type.cc +++ b/src/lib/dcp_content_type.cc @@ -32,7 +32,7 @@ using boost::optional; using namespace std; -vector DCPContentType::_dcp_content_types; +vector DCPContentType::_dcp_content_types; DCPContentType::DCPContentType (string p, dcp::ContentKind k, string d) @@ -48,18 +48,18 @@ void DCPContentType::setup_dcp_content_types () { _dcp_content_types = { - new DCPContentType(_("Feature"), dcp::ContentKind::FEATURE, N_("FTR")), - new DCPContentType(_("Short"), dcp::ContentKind::SHORT, N_("SHR")), - new DCPContentType(_("Trailer"), dcp::ContentKind::TRAILER, N_("TLR")), - new DCPContentType(_("Test"), dcp::ContentKind::TEST, N_("TST")), - new DCPContentType(_("Transitional"), dcp::ContentKind::TRANSITIONAL, N_("XSN")), - new DCPContentType(_("Rating"), dcp::ContentKind::RATING, N_("RTG")), - new DCPContentType(_("Teaser"), dcp::ContentKind::TEASER, N_("TSR")), - new DCPContentType(_("Policy"), dcp::ContentKind::POLICY, N_("POL")), - new DCPContentType(_("Public Service Announcement"), dcp::ContentKind::PUBLIC_SERVICE_ANNOUNCEMENT, N_("PSA")), - new DCPContentType(_("Advertisement"), dcp::ContentKind::ADVERTISEMENT, N_("ADV")), - new DCPContentType(_("Episode"), dcp::ContentKind::EPISODE, N_("EPS")), - new DCPContentType(_("Promo"), dcp::ContentKind::PROMO, N_("PRO")) + DCPContentType(_("Feature"), dcp::ContentKind::FEATURE, N_("FTR")), + DCPContentType(_("Short"), dcp::ContentKind::SHORT, N_("SHR")), + DCPContentType(_("Trailer"), dcp::ContentKind::TRAILER, N_("TLR")), + DCPContentType(_("Test"), dcp::ContentKind::TEST, N_("TST")), + DCPContentType(_("Transitional"), dcp::ContentKind::TRANSITIONAL, N_("XSN")), + DCPContentType(_("Rating"), dcp::ContentKind::RATING, N_("RTG")), + DCPContentType(_("Teaser"), dcp::ContentKind::TEASER, N_("TSR")), + DCPContentType(_("Policy"), dcp::ContentKind::POLICY, N_("POL")), + DCPContentType(_("Public Service Announcement"), dcp::ContentKind::PUBLIC_SERVICE_ANNOUNCEMENT, N_("PSA")), + DCPContentType(_("Advertisement"), dcp::ContentKind::ADVERTISEMENT, N_("ADV")), + DCPContentType(_("Episode"), dcp::ContentKind::EPISODE, N_("EPS")), + DCPContentType(_("Promo"), dcp::ContentKind::PROMO, N_("PRO")) }; } @@ -67,22 +67,22 @@ DCPContentType::setup_dcp_content_types () DCPContentType const * DCPContentType::from_isdcf_name (string n) { - for (auto i: _dcp_content_types) { - if (i->isdcf_name() == n) { - return i; + for (auto& i: _dcp_content_types) { + if (i.isdcf_name() == n) { + return &i; } } - return 0; + return nullptr; } DCPContentType const * DCPContentType::from_libdcp_kind (dcp::ContentKind kind) { - for (auto i: _dcp_content_types) { - if (i->libdcp_kind() == kind) { - return i; + for (auto& i: _dcp_content_types) { + if (i.libdcp_kind() == kind) { + return &i; } } @@ -95,15 +95,15 @@ DCPContentType const * DCPContentType::from_index (int n) { DCPOMATIC_ASSERT (n >= 0 && n < int(_dcp_content_types.size())); - return _dcp_content_types[n]; + return &_dcp_content_types[n]; } optional DCPContentType::as_index (DCPContentType const * c) { - vector::size_type i = 0; - while (i < _dcp_content_types.size() && _dcp_content_types[i] != c) { + vector::size_type i = 0; + while (i < _dcp_content_types.size() && &_dcp_content_types[i] != c) { ++i; } @@ -118,5 +118,9 @@ DCPContentType::as_index (DCPContentType const * c) vector DCPContentType::all () { - return _dcp_content_types; + vector raw; + for (auto& type: _dcp_content_types) { + raw.push_back (&type); + } + return raw; } diff --git a/src/lib/dcp_content_type.h b/src/lib/dcp_content_type.h index 03a52e57c..117ff3b16 100644 --- a/src/lib/dcp_content_type.h +++ b/src/lib/dcp_content_type.h @@ -41,9 +41,6 @@ class DCPContentType public: DCPContentType (std::string, dcp::ContentKind, std::string); - DCPContentType (DCPContentType const&) = delete; - DCPContentType& operator= (DCPContentType const&) = delete; - /** @return user-visible `pretty' name */ std::string pretty_name () const { return _pretty_name; @@ -70,7 +67,7 @@ private: std::string _isdcf_name; /** All available DCP content types */ - static std::vector _dcp_content_types; + static std::vector _dcp_content_types; }; diff --git a/src/lib/filter.cc b/src/lib/filter.cc index 5631af55a..8bf1d0abd 100644 --- a/src/lib/filter.cc +++ b/src/lib/filter.cc @@ -39,7 +39,7 @@ DCPOMATIC_ENABLE_WARNINGS using namespace std; -vector Filter::_filters; +vector Filter::_filters; /** @param i Our id. @@ -61,7 +61,11 @@ Filter::Filter (string i, string n, string c, string f) vector Filter::all () { - return _filters; + vector raw; + for (auto& filter: _filters) { + raw.push_back (&filter); + } + return raw; } @@ -101,7 +105,7 @@ Filter::maybe_add (string i, string n, string c, string f) } if (avfilter_get_by_name(check_name.c_str())) { - _filters.push_back (new Filter(i, n, c, f)); + _filters.push_back (Filter(i, n, c, f)); } } @@ -132,7 +136,7 @@ Filter const * Filter::from_id (string d) { auto i = _filters.begin (); - while (i != _filters.end() && (*i)->id() != d) { + while (i != _filters.end() && i->id() != d) { ++i; } @@ -140,5 +144,5 @@ Filter::from_id (string d) return nullptr; } - return *i; + return &(*i); } diff --git a/src/lib/filter.h b/src/lib/filter.h index 3c2a49792..f73a95453 100644 --- a/src/lib/filter.h +++ b/src/lib/filter.h @@ -44,9 +44,6 @@ class Filter public: Filter (std::string i, std::string n, std::string c, std::string f); - Filter (Filter const&) = delete; - Filter& operator= (Filter const&) = delete; - /** @return our id */ std::string id () const { return _id; @@ -82,7 +79,7 @@ private: std::string _ffmpeg; /** all available filters */ - static std::vector _filters; + static std::vector _filters; static void maybe_add (std::string, std::string, std::string, std::string); }; diff --git a/src/lib/ratio.cc b/src/lib/ratio.cc index 5ba79c28b..aa222b116 100644 --- a/src/lib/ratio.cc +++ b/src/lib/ratio.cc @@ -33,22 +33,33 @@ using std::vector; using boost::optional; -vector Ratio::_ratios; +vector Ratio::_ratios; void Ratio::setup_ratios () { - _ratios.push_back (new Ratio(float(1290) / 1080, "119", _("1.19"), optional(), "119")); - _ratios.push_back (new Ratio(float(1440) / 1080, "133", _("1.33 (4:3)"), optional(), "133")); - _ratios.push_back (new Ratio(float(1485) / 1080, "138", _("1.38 (Academy)"), optional(), "137")); - _ratios.push_back (new Ratio(float(1544) / 1080, "143", _("1.43 (IMAX)"), optional(), "143")); - _ratios.push_back (new Ratio(float(1800) / 1080, "166", _("1.66"), optional(), "166")); - _ratios.push_back (new Ratio(float(1920) / 1080, "178", _("1.78 (16:9 or HD)"), optional(), "178")); - _ratios.push_back (new Ratio(float(1998) / 1080, "185", _("1.85 (Flat)"), string(_("DCI Flat")), "F")); - _ratios.push_back (new Ratio(float(2048) / 872, "235", _("2.35 (35mm Scope)"), optional(), "S")); - _ratios.push_back (new Ratio(float(2048) / 858, "239", _("2.39 (Scope)"), string(_("DCI Scope")), "S")); - _ratios.push_back (new Ratio(float(2048) / 1080, "190", _("1.90 (Full frame)"), string(_("Full frame")), "C")); + _ratios.push_back (Ratio(float(1290) / 1080, "119", _("1.19"), {}, "119")); + _ratios.push_back (Ratio(float(1440) / 1080, "133", _("1.33 (4:3)"), {}, "133")); + _ratios.push_back (Ratio(float(1485) / 1080, "138", _("1.38 (Academy)"), {}, "137")); + _ratios.push_back (Ratio(float(1544) / 1080, "143", _("1.43 (IMAX)"), {}, "143")); + _ratios.push_back (Ratio(float(1800) / 1080, "166", _("1.66"), {}, "166")); + _ratios.push_back (Ratio(float(1920) / 1080, "178", _("1.78 (16:9 or HD)"), {}, "178")); + _ratios.push_back (Ratio(float(1998) / 1080, "185", _("1.85 (Flat)"), string(_("DCI Flat")), "F")); + _ratios.push_back (Ratio(float(2048) / 872, "235", _("2.35 (35mm Scope)"), {}, "S")); + _ratios.push_back (Ratio(float(2048) / 858, "239", _("2.39 (Scope)"), string(_("DCI Scope")), "S")); + _ratios.push_back (Ratio(float(2048) / 1080, "190", _("1.90 (Full frame)"), string(_("Full frame")), "C")); +} + + +vector +Ratio::all () +{ + vector pointers; + for (Ratio& ratio: _ratios) { + pointers.push_back (&ratio); + } + return pointers; } @@ -61,15 +72,15 @@ Ratio::from_id (string i) } auto j = _ratios.begin (); - while (j != _ratios.end() && (*j)->id() != i) { + while (j != _ratios.end() && j->id() != i) { ++j; } - if (j == _ratios.end ()) { - return 0; + if (j == _ratios.end()) { + return nullptr; } - return *j; + return &(*j); } @@ -78,7 +89,7 @@ Ratio const * Ratio::from_ratio (float r) { auto j = _ratios.begin (); - while (j != _ratios.end() && fabs((*j)->ratio() - r) > 0.01) { + while (j != _ratios.end() && fabs(j->ratio() - r) > 0.01) { ++j; } @@ -86,32 +97,34 @@ Ratio::from_ratio (float r) return nullptr; } - return *j; + return &(*j); } Ratio const * Ratio::nearest_from_ratio (float r) { - Ratio const * nearest = nullptr; + vector::const_iterator nearest = _ratios.end(); float distance = FLT_MAX; for (auto i = _ratios.begin(); i != _ratios.end(); ++i) { - float const d = fabs((*i)->ratio() - r); + float const d = fabs(i->ratio() - r); if (d < distance) { distance = d; - nearest = *i; + nearest = i; } } - return nearest; + DCPOMATIC_ASSERT (nearest != _ratios.end()); + + return &(*nearest); } vector Ratio::containers () { if (Config::instance()->allow_any_container()) { - return _ratios; + return all(); } vector r; diff --git a/src/lib/ratio.h b/src/lib/ratio.h index 016a22edc..31ff09358 100644 --- a/src/lib/ratio.h +++ b/src/lib/ratio.h @@ -42,9 +42,6 @@ public: , _isdcf_name (d) {} - Ratio (Ratio const&) = delete; - Ratio& operator= (Ratio const&) = delete; - std::string id () const { return _id; } @@ -72,9 +69,7 @@ public: static Ratio const * from_ratio (float r); static Ratio const * nearest_from_ratio (float r); - static std::vector all () { - return _ratios; - } + static std::vector all (); static std::vector containers (); @@ -88,7 +83,7 @@ private: boost::optional _container_nickname; std::string _isdcf_name; - static std::vector _ratios; + static std::vector _ratios; }; diff --git a/test/ratio_test.cc b/test/ratio_test.cc index 1e8d54333..c922301c2 100644 --- a/test/ratio_test.cc +++ b/test/ratio_test.cc @@ -68,3 +68,12 @@ BOOST_AUTO_TEST_CASE (ratio_test) BOOST_CHECK (r); BOOST_CHECK_EQUAL (fit_ratio_within (r->ratio(), dcp::Size (2048, 1080)), dcp::Size (2048, 1080)); } + + +BOOST_AUTO_TEST_CASE (ratios_use_same_pointers_test) +{ + Ratio::setup_ratios (); + + auto const test = Ratio::from_id ("119"); + BOOST_CHECK_EQUAL (test, Ratio::from_id("119")); +}