Commits

prevent leaks of LogIO and various measures in measures tool, CAS-12488

gcwrap/tools/measures/measures_cmpt.cc

Modified
34 34 #include <measures/Measures/MeasIERS.h>
35 35 #include <measures_cmpt.h>
36 36
37 37 using namespace std;
38 38 using namespace casacore;
39 39 using namespace casa;
40 40
41 41 using namespace casacore;
42 42 namespace casac {
43 43
44 -measures::measures() : pcomet_p(0)
44 +measures::measures(): pcomet_p(nullptr), itsLog(new LogIO())
45 45 {
46 - itsLog = new LogIO();
47 46 casacore::MEpoch tim;
48 47 casacore::MPosition pos;
49 48 casacore::MDirection dir;
50 - frame_p = new MeasFrame(tim,pos,dir);
49 + frame_p.reset(new MeasFrame(tim,pos,dir));
51 50 }
52 51
53 52 measures::~measures()
54 53 {
55 - delete frame_p;
56 - if (pcomet_p) delete pcomet_p;
57 54 MeasIERS::closeTables();
58 55 }
59 56
60 57 // Show a direction formatted
61 58 std::string
62 59 measures::dirshow(const ::casac::record& v)
63 60 {
64 61 std::string outStr("");
65 62 try {
66 63 MeasureHolder mh_dir;
1926 1923 *itsLog << LogIO::SEVERE << error << "Exception Reports: " << x.getMesg() << LogIO::POST;
1927 1924 }
1928 1925 return 0;
1929 1926 }
1930 1927
1931 1928
1932 1929 bool
1933 1930 measures::doframe(const String &in) {
1934 1931 String error;
1935 1932 try {
1936 - delete pcomet_p; pcomet_p = 0;
1933 + pcomet_p.reset(nullptr);
1937 1934 if (in.empty()) {
1938 - pcomet_p = new MeasComet;
1935 + pcomet_p.reset(new MeasComet);
1939 1936 } else {
1940 1937 if(Table::isReadable(in, False)){
1941 1938 Table laTable(in);
1942 1939 Path leSentier(in);
1943 - pcomet_p=new MeasComet(laTable, leSentier.absoluteName());
1940 + pcomet_p.reset(new MeasComet(laTable, leSentier.absoluteName()));
1944 1941 }
1945 1942 else{
1946 - pcomet_p = new MeasComet(in);
1943 + pcomet_p.reset(new MeasComet(in));
1947 1944 }
1948 1945 };
1949 1946 if (!pcomet_p->ok()) {
1950 - delete pcomet_p; pcomet_p = 0;
1947 + pcomet_p.reset(nullptr);
1951 1948 return false;
1952 1949 };
1953 1950 frame_p->set(*pcomet_p);
1954 1951 } catch (AipsError (x)) {
1955 1952 *itsLog << LogIO::SEVERE << error << "Exception Reports: " << x.getMesg()
1956 1953 << LogIO::POST;
1957 1954 RETHROW(x);
1958 1955 return false;
1959 1956 }
1960 1957 return true;
2822 2819 } catch (AipsError(x)) {
2823 2820 *itsLog << LogIO::SEVERE << "Exception Reports: " << x.getMesg() << LogIO::POST;
2824 2821 }
2825 2822 return retval;
2826 2823 }
2827 2824
2828 2825 bool
2829 2826 measures::done()
2830 2827 {
2831 2828 try {
2832 - if (pcomet_p) delete pcomet_p;
2833 - pcomet_p=0;
2834 - delete frame_p;
2835 - frame_p=new MeasFrame();
2829 + frame_p.reset(new MeasFrame());
2836 2830 MeasIERS::closeTables();
2837 2831 return true;
2838 2832 } catch (AipsError(x)) {
2839 2833 *itsLog << LogIO::SEVERE << "Exception Reports: " << x.getMesg() << LogIO::POST;
2840 2834 return false;
2841 2835 }
2842 2836 }
2843 2837
2844 2838 bool
2845 2839 measures::ismeasure(const ::casac::record& a)

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut