Fix svace defects 53/77553/1
authorsangwan.kwon <sangwan.kwon@samsung.com>
Thu, 30 Jun 2016 07:19:02 +0000 (16:19 +0900)
committersangwan.kwon <sangwan.kwon@samsung.com>
Thu, 30 Jun 2016 07:19:02 +0000 (16:19 +0900)
* checker : HANDLE_LEAK.ex

Change-Id: Id0a5dd26f503e204bdd9e710c4f007071dcbf71b
Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
vcore/vcore/Certificate.cpp
vcore/vcore/api.cpp

index 744694c..d2c5c01 100644 (file)
@@ -137,6 +137,10 @@ CertificatePtr Certificate::createFromFile(const std::string &location)
                                          "File content is empty : " << location);
 
        unsigned char *content = new unsigned char[filesize + 1];
+       if (content == NULL)
+               VcoreThrowMsg(Certificate::Exception::InternalError,
+                                         "Fail to allocate memory.");
+
        memset(content, 0x00, filesize + 1);
        rewind(fp);
 
@@ -369,6 +373,12 @@ std::string Certificate::getUID(FieldType type) const
                return std::string();
 
        char *temp = new char[uid->length + 1];
+
+       if(temp == NULL) {
+               LogError("Fail to allocate memory.");
+               return std::string();
+       }
+
        memcpy(temp, uid->data, uid->length);
        temp[uid->length] = 0;
        std::string uidStr(temp);
index 986bb6c..902aa8c 100644 (file)
@@ -1610,17 +1610,19 @@ int certsvc_get_certificate(CertSvcInstance instance,
                        if (fwrite(certBuffer, sizeof(char), length, fp_write) != length) {
                                LogError("Fail to write certificate.");
                                result = CERTSVC_FAIL;
+                               fclose(fp_write);
                                goto error;
                        }
 
-                       fclose(fp_write);
                        result = certsvc_certificate_new_from_file(instance, fileName.c_str(), certificate);
 
                        if (result != CERTSVC_SUCCESS) {
                                LogError("Failed to construct certificate from buffer.");
+                               fclose(fp_write);
                                goto error;
                        }
 
+                       fclose(fp_write);
                        unlink(fileName.c_str());
                }