Fix memory leaks in the Security namespace
[platform/framework/native/appfw.git] / src / security / pkcs / FSecPkcsPkcs08PrivateKeyInfo.cpp
index 5a3d4f0..fd56a52 100644 (file)
@@ -39,8 +39,7 @@ namespace Tizen { namespace Security { namespace Pkcs
 Pkcs08PrivateKeyInfo::Pkcs08PrivateKeyInfo(void)
        : __pPkcs08PrivateKeyInfoImpl(null)
 {
-       __pPkcs08PrivateKeyInfoImpl = new (std::nothrow) _Pkcs08PrivateKeyInfoImpl();
-       SysTryReturnVoidResult(NID_SEC_CRYPTO, __pPkcs08PrivateKeyInfoImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient.");
+
 }
 
 //Default Destructor
@@ -55,9 +54,21 @@ Pkcs08PrivateKeyInfo::Construct(const Tizen::Base::ByteBuffer& encodedData)
 {
        result r = E_SUCCESS;
 
-       SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
+       SysAssertf(__pPkcs08PrivateKeyInfoImpl == null,
+                          "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
+
+       __pPkcs08PrivateKeyInfoImpl = new (std::nothrow) _Pkcs08PrivateKeyInfoImpl();
+       SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs08PrivateKeyInfoImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient.");
+
        r = __pPkcs08PrivateKeyInfoImpl->Construct(encodedData);
-       SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
+       SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
+
+       return r;
+
+CATCH:
+
+       delete __pPkcs08PrivateKeyInfoImpl;
+       __pPkcs08PrivateKeyInfoImpl = null;
 
        return r;
 }
@@ -67,9 +78,22 @@ Pkcs08PrivateKeyInfo::Construct(const AlgorithmIdentifier& privAlgoId, const Tiz
 {
        result r = E_SUCCESS;
 
-       SysAssertf(__pPkcs08PrivateKeyInfoImpl != null, "Not yet constructed. Reconstructor the object.");
+       SysAssertf(__pPkcs08PrivateKeyInfoImpl == null,
+                          "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
+
+       __pPkcs08PrivateKeyInfoImpl = new (std::nothrow) _Pkcs08PrivateKeyInfoImpl();
+       SysTryReturnResult(NID_SEC_CRYPTO, __pPkcs08PrivateKeyInfoImpl != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory in insufficient.");
+
+
        r = __pPkcs08PrivateKeyInfoImpl->Construct(privAlgoId, privKey);
-       SysTryReturn(NID_SEC_CRYPTO, !IsFailed(r), r, r, "[%s] Propagated.", GetErrorMessage(r));
+       SysTryCatch(NID_SEC_CRYPTO, !IsFailed(r), , r, "[%s] Propagated.", GetErrorMessage(r));
+
+       return r;
+
+CATCH:
+
+       delete __pPkcs08PrivateKeyInfoImpl;
+       __pPkcs08PrivateKeyInfoImpl = null;
 
        return r;
 }