Fix DataSet memory leak
authorSeungYeup Kim <sy2004.kim@samsung.com>
Tue, 9 Apr 2013 08:44:51 +0000 (17:44 +0900)
committerSeungYeup Kim <sy2004.kim@samsung.com>
Wed, 10 Apr 2013 01:24:25 +0000 (10:24 +0900)
Change-Id: I495b29c769ff183de804be1fbfcf86c3b8962185

src/io/FIo_DataRowImpl.cpp
src/io/FIo_DataSetEnumeratorImpl.cpp
src/io/FIo_DataSetImpl.cpp [changed mode: 0644->0755]
src/io/inc/FIo_DataSetImpl.h [changed mode: 0644->0755]

index 2bfaa6b..19b0e99 100755 (executable)
@@ -114,17 +114,12 @@ _DataRowImpl::SetBlobAt(int columnIndex, Tizen::Base::ByteBuffer* pValue)
        pItem->size = pValue->GetLimit();
        pItem->pObj = pValue;
 
-       _DataItem* pOldItem = static_cast<_DataItem*>(__pDataRow->GetAt(columnIndex));
        r = __pDataRow->SetAt(pItem.release(), columnIndex);
        SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY,
                        "The memory is insufficient. Set failed");
-       delete pOldItem;
 
        if (nColumnType == DB_COLUMNTYPE_NULL)
-       {
                __pColumnTypeList->SetAt(new Integer(DB_COLUMNTYPE_BLOB), columnIndex);
-               delete pColumnType;
-       }
 
        return r;
 }
@@ -156,17 +151,12 @@ _DataRowImpl::SetDateTimeAt(int columnIndex, const Tizen::Base::DateTime& value)
        pItem->size = pString->GetLength();
        pItem->pObj = pString.release();
 
-       _DataItem* pOldItem = static_cast<_DataItem*>(__pDataRow->GetAt(columnIndex));
        r = __pDataRow->SetAt(pItem.release(), columnIndex);
        SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY,
                        "The memory is insufficient. Set failed");
-       delete pOldItem;
 
        if (nColumnType == DB_COLUMNTYPE_NULL)
-       {
                __pColumnTypeList->SetAt(new Integer(DB_COLUMNTYPE_TEXT), columnIndex);
-               delete pColumnType;
-       }
 
        return r;
 
@@ -196,17 +186,12 @@ _DataRowImpl::SetDoubleAt(int columnIndex, double value)
        pItem->size = size;
        pItem->doubleValue = value;
 
-       _DataItem* pOldItem = static_cast<_DataItem*>(__pDataRow->GetAt(columnIndex));
        r = __pDataRow->SetAt(pItem.release(), columnIndex);
        SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY,
                        "The memory is insufficient. Set failed");
-       delete pOldItem;
 
        if (nColumnType == DB_COLUMNTYPE_NULL)
-       {
                __pColumnTypeList->SetAt(new Integer(DB_COLUMNTYPE_DOUBLE), columnIndex);
-               delete pColumnType;
-       }
 
        return r;
 
@@ -236,17 +221,12 @@ _DataRowImpl::SetIntAt(int columnIndex, int value)
        pItem->size = size;
        pItem->intValue = value;
 
-       _DataItem* pOldItem = static_cast<_DataItem*>(__pDataRow->GetAt(columnIndex));
        r = __pDataRow->SetAt(pItem.release(), columnIndex);
        SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY,
                        "The memory is insufficient. Set failed");
-       delete pOldItem;
 
        if (nColumnType == DB_COLUMNTYPE_NULL)
-       {
                __pColumnTypeList->SetAt(new Integer(DB_COLUMNTYPE_INT), columnIndex);
-               delete pColumnType;
-       }
 
        return r;
 }
@@ -275,17 +255,12 @@ _DataRowImpl::SetInt64At(int columnIndex, long long value)
        pItem->size = size;
        pItem->int64Value = value;
 
-       _DataItem* pOldItem = static_cast<_DataItem*>(__pDataRow->GetAt(columnIndex));
        r = __pDataRow->SetAt(pItem.release(), columnIndex);
        SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY,
                        "The memory is insufficient. Set failed");
-       delete pOldItem;
 
        if (nColumnType == DB_COLUMNTYPE_NULL)
-       {
                __pColumnTypeList->SetAt(new Integer(DB_COLUMNTYPE_INT64), columnIndex);
-               delete pColumnType;
-       }
 
        return r;
 }
@@ -314,17 +289,12 @@ _DataRowImpl::SetStringAt(int columnIndex, const Tizen::Base::String& value)
        pItem->size = value.GetLength();
        pItem->pObj = pString.release();
 
-       _DataItem* pOldItem = static_cast<_DataItem*>(__pDataRow->GetAt(columnIndex));
        r = __pDataRow->SetAt(pItem.release(), columnIndex);
        SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY,
                        "The memory is insufficient. Set failed");
-       delete pOldItem;
 
        if (nColumnType == DB_COLUMNTYPE_NULL)
-       {
                __pColumnTypeList->SetAt(new Integer(DB_COLUMNTYPE_TEXT), columnIndex);
-               delete pColumnType;
-       }
 
        return r;
 }
@@ -372,9 +342,7 @@ _DataRowImpl::Clone(const ArrayList* pOthersRowArrayList) const
                        pItem->pObj = pBuffer;
                }
 
-               _DataItem* pOldItem = static_cast<_DataItem*>(__pDataRow->GetAt(i));
                r = __pDataRow->SetAt(pItem.release(), i);
-               delete pOldItem;
                if (r != E_SUCCESS)
                        break;
        }
index b3e5d8f..c631d7f 100755 (executable)
@@ -70,6 +70,9 @@ _DataSetEnumeratorImpl::~_DataSetEnumeratorImpl(void)
 result
 _DataSetEnumeratorImpl::MoveNext(void)
 {
+       SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
+                               "The Object is not constructed or the dataset is already been deleted.");
+
        if (__currentRowIndex +1  == __rowCount)
                return E_OUT_OF_RANGE;
 
@@ -85,6 +88,9 @@ _DataSetEnumeratorImpl::MoveNext(void)
 result
 _DataSetEnumeratorImpl::MovePrevious(void)
 {
+       SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
+                               "The Object is not constructed or the dataset is already been deleted.");
+
        if (__currentRowIndex == 0)
                return E_OUT_OF_RANGE;
 
@@ -100,6 +106,9 @@ _DataSetEnumeratorImpl::MovePrevious(void)
 result
 _DataSetEnumeratorImpl::MoveFirst(void)
 {
+       SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
+                               "The Object is not constructed or the dataset is already been deleted.");
+
        __currentRowIndex = 0;
        __pCurrentRow = static_cast<ArrayList*>(__pDataSet->GetAt(__currentRowIndex));
 
@@ -112,6 +121,9 @@ _DataSetEnumeratorImpl::MoveFirst(void)
 result
 _DataSetEnumeratorImpl::MoveLast(void)
 {
+       SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
+                               "The Object is not constructed or the dataset is already been deleted.");
+
        __currentRowIndex = __rowCount -1;
        __pCurrentRow = static_cast<ArrayList*>(__pDataSet->GetAt(__currentRowIndex));
 
@@ -124,6 +136,9 @@ _DataSetEnumeratorImpl::MoveLast(void)
 result
 _DataSetEnumeratorImpl::Reset(void)
 {
+       SysTryReturnResult(NID_IO, __pDataSet != null, E_INVALID_STATE,
+                               "The Object is not constructed or the dataset is already been deleted.");
+
        __currentRowIndex = -1;
        __pCurrentRow = null;
 
@@ -383,10 +398,10 @@ _DataSetEnumeratorImpl::GetColumnType(int columnIndex) const
                        return DB_COLUMNTYPE_UNDEFINED;
                }
 
-               type = pDataItem->type;
-               switch (type)
+               switch (pDataItem->type)
                {
                case DB_COLUMNTYPE_INT:
+               case DB_COLUMNTYPE_INT64:
                case DB_COLUMNTYPE_DOUBLE:
                case DB_COLUMNTYPE_TEXT:
                case DB_COLUMNTYPE_BLOB:
@@ -429,13 +444,13 @@ _DataSetEnumeratorImpl::GetColumnSize(int columnIndex) const
 {
        int bytes = 0;
 
-       SysTryReturn(NID_IO, __pDataSet != null, 0, E_INVALID_STATE,
+       SysTryReturn(NID_IO, __pDataSet != null, -1, E_INVALID_STATE,
                                "[E_INVALID_STATE] The instance is not constructed or the dataset is already been deleted.");
 
-       SysTryReturn(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, 0, E_INVALID_ARG,
+       SysTryReturn(NID_IO, columnIndex >= 0 && columnIndex < __columnCount, -1, E_INVALID_ARG,
                                "[E_INVALID_ARG] Given column index is out of range.");
 
-       SysTryReturn(NID_IO, __pCurrentRow != null, 0, E_INVALID_STATE,
+       SysTryReturn(NID_IO, __pCurrentRow != null, -1, E_INVALID_STATE,
                                "[E_INVALID_STATE] The method has tried to fetch the column data of a result set that is not activated.");
 
        _DataItem* pDataItem = dynamic_cast < _DataItem* >(__pCurrentRow->GetAt(columnIndex));
old mode 100644 (file)
new mode 100755 (executable)
index 5f5c250..9670bd3
@@ -37,14 +37,18 @@ using namespace Tizen::Base::Collection;
 namespace Tizen { namespace Io
 {
 _DataSetImpl::_DataSetImpl(void)
-       :__rowCount(0)
+       :__rowCount(0),
+       __pDataSet(null),
+       __pColumnList(null),
+       __pColumnTypeList(null)
 {
-
 }
 
 _DataSetImpl::~_DataSetImpl(void)
 {
-
+       delete __pDataSet;
+       delete __pColumnList;
+       delete __pColumnTypeList;
 }
 
 result
@@ -52,21 +56,28 @@ _DataSetImpl::Construct(const IList& columnNames)
 {
        result r = E_SUCCESS;
 
+       __pDataSet = new (std::nothrow) LinkedList(SingleObjectDeleter);
+       SysTryReturnResult(NID_IO, __pDataSet != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
+       __pColumnList = new (std::nothrow) ArrayList(SingleObjectDeleter);
+       SysTryReturnResult(NID_IO, __pColumnList != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
+       __pColumnTypeList = new (std::nothrow) ArrayList(SingleObjectDeleter);
+       SysTryReturnResult(NID_IO, __pColumnTypeList != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
+
        __columnCount = columnNames.GetCount();
-       SysTryReturn(NID_IO, __columnCount > 0, E_INVALID_ARG, r, "[E_INVALID_ARG] column count is 0.");
+       SysTryReturnResult(NID_IO, __columnCount > 0, E_INVALID_ARG, "column count is 0.");
 
-       r = __columnList.Construct(__columnCount);
+       r = __pColumnList->Construct(__columnCount);
        SysTryReturn(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] column list construct failed");
-       r = __columnTypeList.Construct(__columnCount);
+       r = __pColumnTypeList->Construct(__columnCount);
        SysTryReturn(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] column type list construct failed");
 
        for (int i = 0 ; i < __columnCount ; i++)
        {
-               r = __columnList.Add(new (std::nothrow) String(*(String*)(columnNames.GetAt(i))));
-               SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+               r = __pColumnList->Add(new (std::nothrow) String(*(String*)(columnNames.GetAt(i))));
+               SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, "The memory is insufficient.");
 
-               r = __columnTypeList.Add(new (std::nothrow) Integer(DB_COLUMNTYPE_NULL));
-               SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+               r = __pColumnTypeList->Add(new (std::nothrow) Integer(DB_COLUMNTYPE_NULL));
+               SysTryReturnResult(NID_IO, r == E_SUCCESS, E_OUT_OF_MEMORY, "The memory is insufficient.");
        }
        //SysLog(NID_IO, "column count is %d", __columnCount);
 
@@ -77,18 +88,18 @@ DataRow*
 _DataSetImpl::CreateDataRowN(void)
 {
        result r;
-       unique_ptr<ArrayList> pNewRowArrayList(new (std::nothrow) ArrayList);
+       unique_ptr<ArrayList> pNewRowArrayList(new (std::nothrow) ArrayList(SingleObjectDeleter));
        SysTryReturn(NID_IO, pNewRowArrayList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
        unique_ptr<DataRow> pDataRow(_DataRowImpl::CreateDataRowInstanceN(__columnCount, pNewRowArrayList.get()));
        SysTryReturn(NID_IO, pDataRow != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
-       r = __dataSet.Add(pNewRowArrayList.release());
+       r = __pDataSet->Add(pNewRowArrayList.release());
        SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Add Row to DataSet is failed");
 
-       _DataRowImpl::GetInstance(*pDataRow)->__pColumnTypeList = &__columnTypeList;
+       _DataRowImpl::GetInstance(*pDataRow)->__pColumnTypeList = __pColumnTypeList;
 
-       __rowCount = __dataSet.GetCount();
+       __rowCount = __pDataSet->GetCount();
        //SysLog(NID_IO, "row count is %d", __rowCount);
 
        return pDataRow.release();
@@ -100,8 +111,8 @@ _DataSetImpl::GetDataSetEnumeratorN(void)
 {
        unique_ptr<DataSetEnumerator> pDataSetEnum(_DataSetEnumeratorImpl::CreateDataSetEnumeratorInstanceN());
 
-       _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pDataSet = &__dataSet;
-       _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pColumnList = &__columnList;
+       _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pDataSet = __pDataSet;
+       _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__pColumnList = __pColumnList;
        _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__columnCount = __columnCount;
        _DataSetEnumeratorImpl::GetInstance(*pDataSetEnum)->__rowCount = __rowCount;
 
@@ -114,26 +125,22 @@ DataSet*
 _DataSetImpl::CloneN(void) const
 {
        result r;
-       Integer* pColumnType = null;
 
        unique_ptr< DataSet > pDataSet(new (std::nothrow) DataSet());
        SysTryReturn(NID_IO, pDataSet != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
-       pDataSet->Construct(__columnList);
+       pDataSet->Construct(*__pColumnList);
 
        for (int i = 0; i < __columnCount; i++)
        {
-               pColumnType = static_cast<Integer*>(_DataSetImpl::GetInstance(*pDataSet)->__columnTypeList.GetAt(i));
-               r = _DataSetImpl::GetInstance(*pDataSet)->__columnTypeList.SetAt(new Integer(*(Integer*)__columnTypeList.GetAt(i)), i);
-               delete pColumnType;
-
+               r = _DataSetImpl::GetInstance(*pDataSet)->__pColumnTypeList->SetAt(new Integer(*(Integer*)__pColumnTypeList->GetAt(i)), i);
                SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] ColumnTypeList Copy Falied");
        }
 
        for (int i = 0; i < __rowCount; i++)
        {
                DataRow* pNewRow = pDataSet->CreateDataRowN();
-               r = _DataRowImpl::GetInstance(*pNewRow)->Clone((const ArrayList*)(__dataSet.GetAt(i)));
+               r = _DataRowImpl::GetInstance(*pNewRow)->Clone((const ArrayList*)(__pDataSet->GetAt(i)));
                delete pNewRow;
 
                SysTryReturn(NID_IO, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] DataRow Clone Falied");
@@ -161,7 +168,7 @@ _DataSetImpl::GetHashCode(void) const
 
        for (int i = 0; i < __rowCount; i++)
        {
-               const ArrayList* pDataRowArrayList = static_cast<const ArrayList*>(__dataSet.GetAt(i));
+               const ArrayList* pDataRowArrayList = static_cast<const ArrayList*>(__pDataSet->GetAt(i));
                hash += _DataRowImpl::GetHashCode(pDataRowArrayList);
        }
 
old mode 100644 (file)
new mode 100755 (executable)
index fa1a3a6..2c4fd48
@@ -67,9 +67,9 @@ private:
 
        _DataSetImpl& operator =(const _DataSetImpl& dataSetImpl);
 
-       Tizen::Base::Collection::LinkedList __dataSet;
-       Tizen::Base::Collection::ArrayList __columnList;
-       Tizen::Base::Collection::ArrayList __columnTypeList;
+       Tizen::Base::Collection::LinkedList* __pDataSet;
+       Tizen::Base::Collection::ArrayList* __pColumnList;
+       Tizen::Base::Collection::ArrayList* __pColumnTypeList;
 
        int __columnCount;
        int __rowCount;