Fix the prevent problem
authorWonkyu Kwon <wonkyu.kwon@samsung.com>
Wed, 2 Jan 2013 06:57:08 +0000 (15:57 +0900)
committerWonkyu Kwon <wonkyu.kwon@samsung.com>
Wed, 2 Jan 2013 06:57:08 +0000 (15:57 +0900)
 - fix a resource leak in SignatureHelper.cpp

Change-Id: I8749fcf045feebf79ff05481eeb15859077912a1

common/SignatureHelper.cpp
packaging/smartcard-service.spec

index cf59387..d512bc0 100644 (file)
@@ -221,7 +221,7 @@ namespace smartcard_service_api
 /* export C API */
 using namespace smartcard_service_api;
 
-certiHash__signature_helper_vector_to_linked_list(vector<ByteArray> &certHashes)
+certiHash *__signature_helper_vector_to_linked_list(vector<ByteArray> &certHashes)
 {
        vector<ByteArray>::iterator item;
        certiHash *head, *tail, *tmp;
@@ -230,18 +230,21 @@ certiHash* __signature_helper_vector_to_linked_list(vector<ByteArray> &certHashe
 
        for (item = certHashes.begin(); item != certHashes.end(); item++)
        {
-               if((tmp = (certiHash*)calloc(1, sizeof(certiHash)))== NULL)
+               if ((tmp = (certiHash *)calloc(1, sizeof(certiHash))) == NULL)
                        goto ERROR;
 
                tmp->length = (*item).getLength();
 
-               if((tmp->value = (uint8_t*)calloc(tmp->length, sizeof(uint8_t))) == NULL)
+               if ((tmp->value = (uint8_t *)calloc(tmp->length, sizeof(uint8_t))) == NULL)
+               {
+                       free(tmp);
                        goto ERROR;
+               }
 
                memcpy(tmp->value, (*item).getBuffer(), tmp->length);
                tmp->next = NULL;
 
-               if(head == NULL)
+               if (head == NULL)
                {
                        head = tail = tmp;
                }
@@ -254,19 +257,18 @@ certiHash* __signature_helper_vector_to_linked_list(vector<ByteArray> &certHashe
        return head;
 
 ERROR :
-               SCARD_DEBUG_ERR("mem alloc fail");
+       SCARD_DEBUG_ERR("mem alloc fail");
 
-               while(head)
-               {
-                       tmp = head;
-                       head = head->next;
-                       if(tmp->value != NULL)
-                               free(tmp->value);
-                       free(tmp);
-               }
-
-               return NULL;
+       while (head)
+       {
+               tmp = head;
+               head = head->next;
+               if (tmp->value != NULL)
+                       free(tmp->value);
+               free(tmp);
+       }
 
+       return NULL;
 }
 
 EXTERN_API int signature_helper_get_process_name(int pid, char *processName, uint32_t length)
index 6347749..4da0fcb 100644 (file)
@@ -1,7 +1,7 @@
 Name:       smartcard-service
 Summary:    Smartcard Service FW
-Version:    0.1.4
-Release:    2
+Version:    0.1.7
+Release:    1
 Group:      libs
 License:    Samsung Proprietary License
 Source0:    %{name}-%{version}.tar.gz