Fix memory leak
[platform/core/appfw/data-control.git] / src / data_control_provider.c
index f493df2..1962df9 100755 (executable)
@@ -1245,7 +1245,8 @@ int __datacontrol_send_async(int sockfd, bundle *kb,
        buf = (char *)calloc(datalen + 4, sizeof(char));
        if (buf == NULL) {
                _LOGE("buf calloc error");
-               return DATA_CONTROL_ERROR_OUT_OF_MEMORY;
+               ret = DATA_CONTROL_ERROR_OUT_OF_MEMORY;
+               goto out;
        }
        memcpy(buf, &datalen, sizeof(datalen));
        memcpy(buf + sizeof(datalen), kb_data, datalen);
@@ -1268,7 +1269,8 @@ int __datacontrol_send_async(int sockfd, bundle *kb,
                ret = __send_bulk_result(sockfd, data);
 
 out:
-       free(buf);
+       if (buf)
+               free(buf);
        bundle_free_encoded_rawdata(&kb_data);
 
        return ret;