[Libreoffice-commits] core.git: chart2/source
Takeshi Abe
tabe at fixedpoint.jp
Wed Mar 26 03:06:38 PDT 2014
chart2/source/tools/OPropertySet.cxx | 17 +++++++++--------
chart2/source/view/charttypes/Splines.cxx | 24 +++++++++---------------
2 files changed, 18 insertions(+), 23 deletions(-)
New commits:
commit 3952fab4edb68608dee1e20750a826c6e0c1a417
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date: Wed Mar 26 19:01:15 2014 +0900
Avoid possible resource leaks by boost::scoped_array
Change-Id: I8b57f970b31b12902e3772c3306b71379b8d3fe5
diff --git a/chart2/source/tools/OPropertySet.cxx b/chart2/source/tools/OPropertySet.cxx
index aa4ca40..09a5686 100644
--- a/chart2/source/tools/OPropertySet.cxx
+++ b/chart2/source/tools/OPropertySet.cxx
@@ -25,6 +25,7 @@
#include <vector>
#include <algorithm>
+#include <boost/scoped_array.hpp>
using namespace ::com::sun::star;
@@ -147,11 +148,11 @@ Sequence< beans::PropertyState > SAL_CALL
{
cppu::IPropertyArrayHelper & rPH = getInfoHelper();
- sal_Int32 * pHandles = new sal_Int32[ aPropertyName.getLength() ];
- rPH.fillHandles( pHandles, aPropertyName );
+ boost::scoped_array<sal_Int32> pHandles(new sal_Int32[ aPropertyName.getLength() ]);
+ rPH.fillHandles( pHandles.get(), aPropertyName );
- ::std::vector< sal_Int32 > aHandles( pHandles, pHandles + aPropertyName.getLength());
- delete[] pHandles;
+ ::std::vector< sal_Int32 > aHandles( pHandles.get(), pHandles.get() + aPropertyName.getLength());
+ pHandles.reset();
return m_pImplProperties->GetPropertyStatesByHandle( aHandles );
}
@@ -198,11 +199,11 @@ void SAL_CALL
{
cppu::IPropertyArrayHelper & rPH = getInfoHelper();
- sal_Int32 * pHandles = new sal_Int32[ aPropertyNames.getLength() ];
- rPH.fillHandles( pHandles, aPropertyNames );
+ boost::scoped_array<sal_Int32> pHandles(new sal_Int32[ aPropertyNames.getLength() ]);
+ rPH.fillHandles( pHandles.get(), aPropertyNames );
- ::std::vector< sal_Int32 > aHandles( pHandles, pHandles + aPropertyNames.getLength());
- delete[] pHandles;
+ ::std::vector< sal_Int32 > aHandles( pHandles.get(), pHandles.get() + aPropertyNames.getLength());
+ pHandles.reset();
m_pImplProperties->SetPropertiesToDefault( aHandles );
}
diff --git a/chart2/source/view/charttypes/Splines.cxx b/chart2/source/view/charttypes/Splines.cxx
index e770b4b..419fb9a 100644
--- a/chart2/source/view/charttypes/Splines.cxx
+++ b/chart2/source/view/charttypes/Splines.cxx
@@ -23,6 +23,7 @@
#include <vector>
#include <algorithm>
#include <functional>
+#include <boost/scoped_array.hpp>
#define MAX_BSPLINE_DEGREE 15
@@ -727,30 +728,29 @@ void SplineCalculater::CalculateBSplines(
continue; // need at least 2 points, degree p needs at least n+1 points
// next piece of series
- double* t = new double [n+1];
- if (!createParameterT(aPointsIn, t))
+ boost::scoped_array<double> t(new double [n+1]);
+ if (!createParameterT(aPointsIn, t.get()))
{
- delete[] t;
continue; // next piece of series
}
lcl_tSizeType m = n + p + 1;
- double* u = new double [m+1];
- createKnotVector(n, p, t, u);
+ boost::scoped_array<double> u(new double [m+1]);
+ createKnotVector(n, p, t.get(), u.get());
// The matrix N contains the B-spline basis functions applied to parameters.
// In each row only p+1 adjacent elements are non-zero. The starting
// column in a higher row is equal or greater than in the lower row.
// To store this matrix the non-zero elements are shifted to column 0
// and the amount of shifting is remembered in an array.
- double** aMatN = new double*[n+1];
+ boost::scoped_array<double*> aMatN(new double*[n+1]);
for (lcl_tSizeType row = 0; row <=n; ++row)
{
aMatN[row] = new double[p+1];
for (sal_uInt32 col = 0; col <= p; ++col)
aMatN[row][col] = 0.0;
}
- lcl_tSizeType* aShift = new lcl_tSizeType[n+1];
+ boost::scoped_array<lcl_tSizeType> aShift(new lcl_tSizeType[n+1]);
aMatN[0][0] = 1.0; //all others are zero
aShift[0] = 0;
aMatN[n][0] = 1.0;
@@ -770,7 +770,7 @@ void SplineCalculater::CalculateBSplines(
// index in reduced matrix aMatN = (index in full matrix N) - (i-p)
aShift[k] = i - p;
- applyNtoParameterT(i, t[k], p, u, aMatN[k]);
+ applyNtoParameterT(i, t[k], p, u.get(), aMatN[k]);
} // next row k
// Get matrix C of control points from the matrix equation aMatN * C = aPointsIn
@@ -886,7 +886,7 @@ void SplineCalculater::CalculateBSplines(
pNewX[nNewSize -1 ] = aPointsIn[n].first;
pNewY[nNewSize -1 ] = aPointsIn[n].second;
pNewZ[nNewSize -1 ] = fZCoordinate;
- double* aP = new double[m+1];
+ boost::scoped_array<double> aP(new double[m+1]);
lcl_tSizeType nLow = 0;
for ( lcl_tSizeType nTIndex = 0; nTIndex <= n-1; ++nTIndex)
{
@@ -939,17 +939,11 @@ void SplineCalculater::CalculateBSplines(
pNewZ[nNewIndex] = fZCoordinate;
}
}
- delete[] aP;
}
- delete[] aShift;
for (lcl_tSizeType row = 0; row <=n; ++row)
{
delete[] aMatN[row];
}
- delete[] aMatN;
- delete[] u;
- delete[] t;
-
} // next piece of the series
}
More information about the Libreoffice-commits
mailing list