1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #include "hcs_mem.h" 10 #include <stdint.h> 11 #include <stdlib.h> 12 #include <securec.h> 13 #define MEM_MAX (1024 * 1024) 14 HcsMemAlloc(uint32_t size)15void *HcsMemAlloc(uint32_t size) 16 { 17 if (size == 0 || size > MEM_MAX) { 18 return NULL; 19 } 20 21 return malloc(size); 22 } 23 HcsMemZalloc(uint32_t size)24void *HcsMemZalloc(uint32_t size) 25 { 26 void *newMem = HcsMemAlloc(size); 27 if (newMem == NULL) { 28 return NULL; 29 } 30 (void)memset_s(newMem, size, 0, size); 31 return newMem; 32 } 33 HcsMemFree(void * ptr)34void HcsMemFree(void *ptr) 35 { 36 if (ptr != NULL) { 37 free(ptr); 38 } 39 }