Fix prevent defect.
authorHokwon Song <hokwon.song@samsung.com>
Mon, 21 Oct 2013 11:23:06 +0000 (20:23 +0900)
committerHokwon Song <hokwon.song@samsung.com>
Mon, 21 Oct 2013 11:23:06 +0000 (20:23 +0900)
Change-Id: I558791c3b510fe56fc358223d601e09c8d79957f
Signed-off-by: Hokwon Song <hokwon.song@samsung.com>
src/system/FSys_AlarmExStub.cpp

index d9833f3..41b5a28 100644 (file)
@@ -125,17 +125,17 @@ _AlarmExStub::ExportToFile(const String &path)
        result r = E_SUCCESS;
        SysLog(NID_SYS, "ExportToFile");
        int error = -1;
-       char* pSmackLable = _StringConverter::CopyToCharArrayN(__clientPackageId);
-       char* pPath = _StringConverter::CopyToCharArrayN(path);
-       error = alarm_backup(pPath);
+       std::unique_ptr<char[]> pSmackLable(_StringConverter::CopyToCharArrayN(__clientPackageId));
+       std::unique_ptr<char[]> pPath(_StringConverter::CopyToCharArrayN(path));
+       error = alarm_backup(pPath.get());
        SysLog(NID_SYS, "alarm_backup returns [%d]", error);
 
        if (error == 0)
         {
                 r = E_SUCCESS;
-               int errorCode = chown(pPath, 5000, 5000);
-               SysTryCatch(NID_SYS, errorCode == 0, r = E_SYSTEM, E_SYSTEM, "It is failed to change permission.");
-               SysTryCatch(NID_SYS, smack_setlabel(pPath, pSmackLable, SMACK_LABEL_ACCESS) == 0, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] SMACK labeling failed");
+               int errorCode = chown(pPath.get(), 5000, 5000);
+               SysTryReturnResult(NID_SYS, errorCode == 0, E_SYSTEM, "It is failed to change permission.");
+               SysTryReturnResult(NID_SYS, smack_setlabel(pPath.get(), pSmackLable.get(), SMACK_LABEL_ACCESS) == 0, E_SYSTEM, "[E_SYSTEM] SMACK labeling failed");
         }
         else if (error == 1)
        {
@@ -145,9 +145,6 @@ _AlarmExStub::ExportToFile(const String &path)
         {
                 r = E_FAILURE;
         }
-CATCH:
-       delete pSmackLable;
-        delete pPath;
 
        return r;
 }
@@ -158,10 +155,9 @@ _AlarmExStub::ImportFromFile(const String &path)
        result r = E_SUCCESS;
        SysLog(NID_SYS, "ImportFromFile");
        int error = -1;
-       char* pPath = _StringConverter::CopyToCharArrayN(path);
-       error = alarm_restore(pPath);
+       std::unique_ptr<char[]> pPath( _StringConverter::CopyToCharArrayN(path));
+       error = alarm_restore(pPath.get());
        SysLog(NID_SYS, "alarm_restore returns [%d]", error);
-       delete pPath;
 
        if (error == 0)
        {