1 /* 2 * Copyright (c) 2025 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 "ipc_types.h" 17 #include "securec.h" 18 #include "uri_permission_raw_data.h" 19 20 namespace OHOS { 21 namespace AAFwk { RawDataCpy(const void * readdata)22int32_t UriPermissionRawData::RawDataCpy(const void* readdata) 23 { 24 if (readdata == nullptr || size == 0) { 25 return ERR_INVALID_DATA; 26 } 27 void* newData = malloc(size); 28 isMalloc = true; 29 if (newData == nullptr) { 30 isMalloc = false; 31 return ERR_INVALID_DATA; 32 } 33 if (memcpy_s(newData, size, readdata, size) != EOK) { 34 free(newData); 35 isMalloc = false; 36 return ERR_INVALID_DATA; 37 } 38 if (data != nullptr) { 39 free(const_cast<void*>(data)); 40 data = nullptr; 41 } 42 data = newData; 43 return ERR_NONE; 44 } 45 ~UriPermissionRawData()46UriPermissionRawData::~UriPermissionRawData() 47 { 48 if (data != nullptr && isMalloc) { 49 free(const_cast<void*>(data)); 50 isMalloc = false; 51 data = nullptr; 52 } 53 } 54 } // namespace AAFwk 55 } // namespace OHOS