From c85820204393722564a7d697cbd77b4f5aa09bea Mon Sep 17 00:00:00 2001
From: Thomas Habets <thomas@habets.se>
Date: Wed, 12 Aug 2020 11:11:11 +0100
Subject: digital/symbol_sync: Remove manual memory management

The `cc` version already used more smart pointers, but `d_clock`
didn't need to be a pointer at all.

I consted function args to make it clear in the initializer that they
will not be changed in the constructor body.

Return value for `make` for the TED and interpolator was changed to a
`unique_ptr` to make it clear that ownership is transferred. And it
makes it all but impossible to accidentally memory leak.
(core guidelines F.26. Also relevant I.11,R.20).
---
 gr-digital/lib/timing_error_detector.cc | 39 ++++++++++++---------------------
 1 file changed, 14 insertions(+), 25 deletions(-)

(limited to 'gr-digital/lib/timing_error_detector.cc')

diff --git a/gr-digital/lib/timing_error_detector.cc b/gr-digital/lib/timing_error_detector.cc
index e1ceed151e..52bb063948 100644
--- a/gr-digital/lib/timing_error_detector.cc
+++ b/gr-digital/lib/timing_error_detector.cc
@@ -14,49 +14,38 @@
 
 #include "timing_error_detector.h"
 #include <gnuradio/math.h>
+#include <boost/make_unique.hpp>
 #include <stdexcept>
 
 namespace gr {
 namespace digital {
 
-timing_error_detector* timing_error_detector::make(enum ted_type type,
-                                                   constellation_sptr constellation)
+std::unique_ptr<timing_error_detector>
+timing_error_detector::make(enum ted_type type, constellation_sptr constellation)
 {
-    timing_error_detector* ret = NULL;
     switch (type) {
     case TED_NONE:
-        break;
+        return nullptr;
     case TED_MUELLER_AND_MULLER:
-        ret = new ted_mueller_and_muller(constellation);
-        break;
+        return boost::make_unique<ted_mueller_and_muller>(constellation);
     case TED_MOD_MUELLER_AND_MULLER:
-        ret = new ted_mod_mueller_and_muller(constellation);
-        break;
+        return boost::make_unique<ted_mod_mueller_and_muller>(constellation);
     case TED_ZERO_CROSSING:
-        ret = new ted_zero_crossing(constellation);
-        break;
+        return boost::make_unique<ted_zero_crossing>(constellation);
     case TED_GARDNER:
-        ret = new ted_gardner();
-        break;
+        return boost::make_unique<ted_gardner>();
     case TED_EARLY_LATE:
-        ret = new ted_early_late();
-        break;
+        return boost::make_unique<ted_early_late>();
     case TED_DANDREA_AND_MENGALI_GEN_MSK:
-        ret = new ted_generalized_msk();
-        break;
+        return boost::make_unique<ted_generalized_msk>();
     case TED_SIGNAL_TIMES_SLOPE_ML:
-        ret = new ted_signal_times_slope_ml();
-        break;
+        return boost::make_unique<ted_signal_times_slope_ml>();
     case TED_SIGNUM_TIMES_SLOPE_ML:
-        ret = new ted_signum_times_slope_ml();
-        break;
+        return boost::make_unique<ted_signum_times_slope_ml>();
     case TED_MENGALI_AND_DANDREA_GMSK:
-        ret = new ted_gaussian_msk();
-        break;
-    default:
-        break;
+        return boost::make_unique<ted_gaussian_msk>();
     }
-    return ret;
+    return nullptr;
 }
 
 timing_error_detector::timing_error_detector(enum ted_type type,
-- 
cgit v1.2.3