fix mem leaks
authorjungmin76.park <jungmin76.park@samsung.com>
Wed, 26 Jun 2013 11:47:10 +0000 (20:47 +0900)
committerjungmin76.park <jungmin76.park@samsung.com>
Thu, 27 Jun 2013 08:05:22 +0000 (17:05 +0900)
Change-Id: I3811e554ad088de28a4bd1223d8081a5dac5f63f
Signed-off-by: jungmin76.park <jungmin76.park@samsung.com>
src/FShell_AppWidgetProviderInfoImpl.cpp
src/inc/FShell_AppWidgetProviderInfoImpl.h

index 2a10f52..5d53343 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <unique_ptr.h>
 #include <livebox-service/livebox-service.h>
+#include <FApp.h>
 #include <FBase.h>
 #include <FBaseSysLog.h>
 #include <FBase_StringConverter.h>
@@ -45,42 +46,24 @@ using namespace Tizen::Graphics;
 _AppWidgetProviderInfoImpl::_AppWidgetProviderInfoImpl(const Tizen::App::AppId& appId, const Tizen::Base::String& name)
        :__appId(appId)
        ,__name(name)
+       ,__pDisplayName(null)
+    ,__pConfigurationAppControlAppId(null)
+    ,__pIconPath(null)
+       ,__pProviderId(null)
        ,__isDefault(false)
 {
-       __providerId = _AppWidgetManagerImpl::MakeProviderName(appId, name);
+       String providerId = _AppWidgetManagerImpl::MakeProviderName(appId, name);
+       __pProviderId = _StringConverter::CopyToCharArrayN(providerId);
 
-       std::unique_ptr<char[]> pProviderId(_StringConverter::CopyToCharArrayN(__providerId));
-
-       std::unique_ptr<char[]> pDisplayName(livebox_service_i18n_name(pProviderId.get(), null));
-       SysTryReturnVoidResult(NID_SHELL, pDisplayName, E_SYSTEM, "[E_SYSTEM] Propagating.");
-
-       std::unique_ptr<char[]> pSetUpAppId(livebox_service_setup_appid(pProviderId.get()));
-
-       __displayName = pDisplayName.get();
-       __configurationAppControlAppId = pSetUpAppId.get();
-
-       SysSecureLog(NID_SHELL, "appId(%ls), name(%ls), providerId(%ls), displayName(%ls), configuration(%ls)", appId.GetPointer(), name.GetPointer(), __providerId.GetPointer(), __displayName.GetPointer(), __configurationAppControlAppId.GetPointer() );
+       SysSecureLog(NID_SHELL, "appId(%ls), name(%ls), providerId(%s)", appId.GetPointer(), name.GetPointer(), __pProviderId);
 }
 
-/*_AppWidgetProviderInfoImpl::_AppWidgetProviderInfoImpl(const _AppWidgetProviderInfoImpl& rhs)
-{
-       __appId = rhs.__appId;
-       __name = rhs.__name;
-       __providerId = rhs.__providerId;
-}
-
-_AppWidgetProviderInfoImpl&
-_AppWidgetProviderInfoImpl::operator =(const _AppWidgetProviderInfoImpl& rhs)
-{
-       __appId = rhs.__appId;
-       __name = rhs.__name;
-       __providerId = rhs.__providerId;
-
-       return *this;
-}*/
-
 _AppWidgetProviderInfoImpl::~_AppWidgetProviderInfoImpl()
 {
+       delete[] __pProviderId;
+       delete __pDisplayName;
+       delete __pConfigurationAppControlAppId;
+       delete __pIconPath;
 }
 
 Tizen::App::AppId
@@ -96,24 +79,37 @@ _AppWidgetProviderInfoImpl::GetName() const
 }
 
 Tizen::Base::String
-_AppWidgetProviderInfoImpl::GetDisplayName() const
+_AppWidgetProviderInfoImpl::GetDisplayName()
 {
-       return __displayName;
+       if (__pDisplayName == null)
+       {
+               std::unique_ptr<char> pDisplayName(livebox_service_i18n_name(__pProviderId, null));
+               __pDisplayName = new(std::nothrow) String(pDisplayName.get());
+       }
+       return *__pDisplayName;
 }
 
 Tizen::Base::String
-_AppWidgetProviderInfoImpl::GetIconPath() const
+_AppWidgetProviderInfoImpl::GetIconPath()
 {
-       std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(__providerId));
-       String iconPath = livebox_service_i18n_icon(pPackageId.get(), null);
+       if (__pIconPath == null)
+       {
+               std::unique_ptr<char> pIconPath(livebox_service_i18n_icon(__pProviderId, null) );
+               __pIconPath = new(std::nothrow) String(pIconPath.get());
+       }
 
-       return iconPath;
+       return *__pIconPath;
 }
 
 Tizen::Base::String
-_AppWidgetProviderInfoImpl::GetConfigurationAppControlAppId() const
+_AppWidgetProviderInfoImpl::GetConfigurationAppControlAppId()
 {
-       return __configurationAppControlAppId;
+       if (__pConfigurationAppControlAppId == null)
+       {
+               std::unique_ptr<char> pSetUpAppId(livebox_service_setup_appid(__pProviderId));
+               __pConfigurationAppControlAppId = new(std::nothrow) String(pSetUpAppId.get());
+       }
+       return *__pConfigurationAppControlAppId;
 }
 
 bool
@@ -132,10 +128,10 @@ _AppWidgetProviderInfoImpl::GetPrivilegeLevel(const AppId& appId)
        String pkgId = Package::_PackageManagerImpl::GetPackageIdByAppId(appId);
        SysTryReturn(NID_APP, !pkgId.IsEmpty(), _API_VISIBILITY_PUBLIC, E_INVALID_STATE, "Invalid appId(%ls).", appId.GetPointer() );
 
-       Package::PackageInfo* pInfo = pPkg->GetPackageInfoN(pkgId);
+       std::unique_ptr<Package::PackageInfo> pInfo (pPkg->GetPackageInfoN(pkgId) );
        SysTryReturn(NID_APP, pInfo != null, _API_VISIBILITY_PUBLIC, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       const Package::_PackageInfoImpl* pPkgInfo = Package::_PackageInfoImpl::GetInstance(pInfo);
+       const Package::_PackageInfoImpl* pPkgInfo = Package::_PackageInfoImpl::GetInstance(pInfo.get());
        SysTryReturn(NID_APP, pPkgInfo != null, _API_VISIBILITY_PUBLIC, E_INVALID_STATE, "Invalid PackageInfo instance.");
 
        return pPkgInfo->GetApiVisibility();
@@ -177,10 +173,9 @@ _AppWidgetProviderInfoImpl::GetSizeInfoListN() const
        int widthArray[MAX_SUPPORTED_SIZE_TYPE];
        int heightArray[MAX_SUPPORTED_SIZE_TYPE];
 
-       std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(__providerId));
-       livebox_service_get_supported_sizes(pPackageId.get(), &supportedSizeCount , widthArray, heightArray);
+       livebox_service_get_supported_sizes(__pProviderId, &supportedSizeCount , widthArray, heightArray);
 
-       SysTryReturn(NID_SHELL, supportedSizeCount > 0, null, E_SYSTEM, "[E_SYSTEM] There is no appwidget of provider(%ls)",__providerId.GetPointer() );
+       SysTryReturn(NID_SHELL, supportedSizeCount > 0, null, E_SYSTEM, "[E_SYSTEM] There is no appwidget of provider(%s)",__pProviderId );
 
        std::unique_ptr<ArrayList> pSizes(new (std::nothrow) ArrayList);
        SysTryReturn(NID_SHELL, pSizes, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory for ArrayList." );
@@ -192,7 +187,7 @@ _AppWidgetProviderInfoImpl::GetSizeInfoListN() const
        for(int i = 0; i < supportedSizeCount; i++)
        {
                size.SetSize(widthArray[i], heightArray[i]);
-               previewImagePath  = livebox_service_preview(pPackageId.get(), livebox_service_size_type(static_cast<int>(size.width), static_cast<int>(size.height) ) );
+               previewImagePath  = livebox_service_preview(__pProviderId, livebox_service_size_type(static_cast<int>(size.width), static_cast<int>(size.height) ) );
 
                if( IsValidSize(__appId, size.width, size.height) == false )
                {
@@ -201,7 +196,7 @@ _AppWidgetProviderInfoImpl::GetSizeInfoListN() const
 
                int sizeType = livebox_service_size_type(size.width, size.height);
                SysAssertf(sizeType != LB_SIZE_TYPE_UNKNOWN, "Failed to invoke livebox_service_size_type(%d, %d)", size.width, size.height);
-               bool useDecoration = livebox_service_need_frame(pPackageId.get(), sizeType);
+               bool useDecoration = livebox_service_need_frame(__pProviderId, sizeType);
 
                std::unique_ptr<AppWidgetSizeInfo> pAppWidgetSizeInfo(_AppWidgetSizeInfoImpl::CreateAppWidgetSizeInfo(size, previewImagePath, useDecoration) );
                SysTryReturn(NID_SHELL, pAppWidgetSizeInfo, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory for AppWidgetSizeInfo." );
@@ -239,7 +234,7 @@ _AppWidgetProviderInfoImpl::IsExist(const Tizen::App::AppId& appId, const Tizen:
        SysTryReturn(NID_SHELL, Tizen::App::_Aul::IsInstalled(appId) == true, false, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", appId.GetPointer());
 
        std::unique_ptr<char[]> pProviderId(_StringConverter::CopyToCharArrayN(_AppWidgetManagerImpl::MakeProviderName(appId, providerName)));
-       std::unique_ptr<char[]> pPackageId(livebox_service_appid(pProviderId.get()));
+       std::unique_ptr<char> pPackageId( livebox_service_appid(pProviderId.get()) );
        SysTryReturn(NID_SHELL, pPackageId.get(), false, E_APP_NOT_INSTALLED, "The application(%ls) is not installed.", appId.GetPointer());
 
        return true;
index 66de7ec..394b54c 100644 (file)
@@ -76,7 +76,7 @@ public:
         *
         * @return      The display name of the Livbox
         */
-       Tizen::Base::String GetDisplayName() const;
+       Tizen::Base::String GetDisplayName();
 
        /**
         * Gets the icon path of the application.
@@ -86,9 +86,9 @@ public:
         * @return      The icon path of the application, @n
         * An empty string is returned if there is no value.
         */
-       Tizen::Base::String GetIconPath() const;
+       Tizen::Base::String GetIconPath();
 
-       Tizen::Base::String GetConfigurationAppControlAppId() const;
+       Tizen::Base::String GetConfigurationAppControlAppId();
 
        bool IsDefault() const;
 
@@ -105,7 +105,6 @@ public:
         */
     Tizen::Base::Collection::IList* GetSizeInfoListN() const;
 
-
     // internal
     static AppWidgetProviderInfo* GetAppWidgetProviderInfoN(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName);
     static AppWidgetProviderInfo* GetAppWidgetProviderInfoN(const Tizen::App::AppId& appId, const Tizen::Base::String& providerName, bool isDefault);
@@ -149,10 +148,12 @@ private:
 private:
     Tizen::Base::String __appId;
     Tizen::Base::String __name;
+    Tizen::Base::String* __pDisplayName;
+    Tizen::Base::String* __pConfigurationAppControlAppId;
+    Tizen::Base::String* __pIconPath;
+    char* __pProviderId;
     bool __isDefault;
-    Tizen::Base::String __providerId;
-    Tizen::Base::String __displayName; //TODO:temporary public
-    Tizen::Base::String __configurationAppControlAppId; //TODO:temporary public
+
 
 //    Tizen::Base::String __iconPath;
     Tizen::Base::Collection::ArrayList __sizeInfos;