• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *    http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "cf_blob.h"
17 
18 #include <securec.h>
19 #include "cf_memory.h"
20 #include "cf_log.h"
21 #include "cf_result.h"
22 
CfBlobDataFree(CfBlob * blob)23 void CfBlobDataFree(CfBlob *blob)
24 {
25     if ((blob == NULL) || (blob->data == NULL)) {
26         return;
27     }
28     CfFree(blob->data);
29     blob->data = NULL;
30     blob->size = 0;
31 }
32 
CfBlobDataClearAndFree(CfBlob * blob)33 void CfBlobDataClearAndFree(CfBlob *blob)
34 {
35     if ((blob == NULL) || (blob->data == NULL)) {
36         LOGD("The input blob is null, no need to free.");
37         return;
38     }
39     (void)memset_s(blob->data, blob->size, 0, blob->size);
40     CfFree(blob->data);
41     blob->data = NULL;
42     blob->size = 0;
43 }
44 
CfEncodingBlobDataFree(CfEncodingBlob * encodingBlob)45 void CfEncodingBlobDataFree(CfEncodingBlob *encodingBlob)
46 {
47     if ((encodingBlob == NULL) || (encodingBlob->data == NULL)) {
48         LOGD("The input encodingBlob is null, no need to free.");
49         return;
50     }
51     CfFree(encodingBlob->data);
52     encodingBlob->data = NULL;
53     encodingBlob->len = 0;
54 }
55 
CfArrayDataClearAndFree(CfArray * array)56 void CfArrayDataClearAndFree(CfArray *array)
57 {
58     if (array == NULL) {
59         LOGD("The input array is null, no need to free.");
60         return;
61     }
62     for (uint32_t i = 0; i < array->count; ++i) {
63         CfFree(array->data[i].data);
64         array->data[i].data = NULL;
65         array->data[i].size = 0;
66     }
67     array->count = 0;
68     CfFree(array->data);
69     array->data = NULL;
70 }
71 
FreeCfBlobArray(CfBlob * array,uint32_t arrayLen)72 void FreeCfBlobArray(CfBlob *array, uint32_t arrayLen)
73 {
74     if (array == NULL) {
75         return;
76     }
77 
78     for (uint32_t i = 0; i < arrayLen; ++i) {
79         array[i].size = 0;
80         CF_FREE_PTR(array[i].data);
81     }
82 
83     CfFree(array);
84 }
85