diff --git a/components/fs/fatfs/fatfs.c b/components/fs/fatfs/fatfs.c index 11a197df..89b59924 100644 --- a/components/fs/fatfs/fatfs.c +++ b/components/fs/fatfs/fatfs.c @@ -46,6 +46,7 @@ #include "vfs_partition.h" #include "vfs_maps.h" #include "vfs_mount.h" +#include "los_fs.h" /* the max name length of different parts should not bigger than 32 */ #define FS_DRIVE_NAME_MAX_LEN 32 @@ -244,7 +245,7 @@ char * GetLdPath(const char *source) } char *volPath = g_volPath[partId]; - char *ldPath = (char *)malloc(strlen(volPath) + LDPATH_PAD); + char *ldPath = (char *)LOSCFG_FS_MALLOC_HOOK(strlen(volPath) + LDPATH_PAD); if (ldPath == NULL) { return NULL; } @@ -255,7 +256,7 @@ char * GetLdPath(const char *source) *ldPath = '/'; ret = strcpy_s(ldPath + 1, strlen(volPath)+1, volPath); if (ret != EOK) { - free(ldPath); + LOSCFG_FS_FREE_HOOK(ldPath); return NULL; } @@ -265,7 +266,7 @@ char * GetLdPath(const char *source) void PutLdPath(const char *ldPath) { if (ldPath != NULL) { - free((void *)ldPath); + LOSCFG_FS_FREE_HOOK((void *)ldPath); } } @@ -295,7 +296,7 @@ int FatfsMount(struct MountPoint *mp, unsigned long mountflags, goto ERROUT; } - fs = (FATFS *)malloc(sizeof(FATFS)); + fs = (FATFS *)LOSCFG_FS_MALLOC_HOOK(sizeof(FATFS)); if (fs == NULL) { errno = ENOMEM; ret = (int)LOS_NOK; @@ -316,7 +317,7 @@ int FatfsMount(struct MountPoint *mp, unsigned long mountflags, return (int)LOS_OK; ERROUT: - free(fs); + LOSCFG_FS_FREE_HOOK(fs); mp->mData = NULL; PutLdPath(ldPath); FsUnlock(); @@ -369,7 +370,7 @@ int FatfsUmount(struct MountPoint *mp) ff_memfree(fatfs->win); } - free(mp->mData); + LOSCFG_FS_FREE_HOOK(mp->mData); mp->mData = NULL; ret = (int)LOS_OK; @@ -424,7 +425,7 @@ int FatfsUmount2(struct MountPoint *mp, int flag) ff_memfree(fatfs->win); } - free(mp->mData); + LOSCFG_FS_FREE_HOOK(mp->mData); mp->mData = NULL; ret = (int)LOS_OK; @@ -449,7 +450,7 @@ int FatfsOpen(struct File *file, const char *path, int oflag) fmode = FatFsGetMode(oflag); - fp = (FIL *)malloc(sizeof(FIL)); + fp = (FIL *)LOSCFG_FS_MALLOC_HOOK(sizeof(FIL)); if (fp == NULL) { errno = ENOMEM; return (int)LOS_NOK; @@ -458,7 +459,7 @@ int FatfsOpen(struct File *file, const char *path, int oflag) ret = FsLock(); if (ret != 0) { errno = ret; - free(fp); + LOSCFG_FS_FREE_HOOK(fp); return (int)LOS_NOK; } @@ -467,14 +468,14 @@ int FatfsOpen(struct File *file, const char *path, int oflag) PRINT_ERR("FAT open ChangeDrive err 0x%x!\r\n", ret); errno = ENOENT; ret = (int)LOS_NOK; - free(fp); + LOSCFG_FS_FREE_HOOK(fp); goto OUT; } res = f_open(fp, path, fmode); if (res != FR_OK) { PRINT_ERR("FAT open err 0x%x!\r\n", res); - free(fp); + LOSCFG_FS_FREE_HOOK(fp); errno = FatfsErrno(res); ret = (int)LOS_NOK; goto OUT; @@ -518,7 +519,7 @@ int FatfsClose(struct File *file) (void)ff_memfree(fp->buf); } #endif - free(file->fData); + LOSCFG_FS_FREE_HOOK(file->fData); file->fData = NULL; FsUnlock(); @@ -833,7 +834,7 @@ int FatfsOpendir(struct Dir *dir, const char *dirName) goto ERROUT; } - dp = (DIR *)malloc(sizeof(DIR)); + dp = (DIR *)LOSCFG_FS_MALLOC_HOOK(sizeof(DIR)); if (dp == NULL) { errno = ENOENT; goto ERROUT; @@ -867,7 +868,7 @@ int FatfsOpendir(struct Dir *dir, const char *dirName) ERROUT: if (dp != NULL) { - free(dp); + LOSCFG_FS_FREE_HOOK(dp); } FsUnlock(); return (int)LOS_NOK; @@ -939,7 +940,7 @@ int FatfsClosedir(struct Dir *dir) return (int)LOS_NOK; } - free(dir->dData); + LOSCFG_FS_FREE_HOOK(dir->dData); dir->dData = NULL; FsUnlock(); diff --git a/components/fs/littlefs/lfs_adapter.c b/components/fs/littlefs/lfs_adapter.c index 3f161074..5af2fb5f 100644 --- a/components/fs/littlefs/lfs_adapter.c +++ b/components/fs/littlefs/lfs_adapter.c @@ -39,6 +39,7 @@ #include "vfs_maps.h" #include "vfs_mount.h" #include "securec.h" +#include "los_fs.h" static pthread_mutex_t g_fsLocalMutex = PTHREAD_MUTEX_INITIALIZER; @@ -190,7 +191,7 @@ int LfsMount(struct MountPoint *mp, unsigned long mountflags, const void *data) goto errout; } - mountHdl = (lfs_t *)malloc(sizeof(lfs_t) + sizeof(struct lfs_config)); + mountHdl = (lfs_t *)LOSCFG_FS_MALLOC_HOOK(sizeof(lfs_t) + sizeof(struct lfs_config)); if (mountHdl == NULL) { errno = ENODEV; ret = (int)LOS_NOK; @@ -210,7 +211,7 @@ int LfsMount(struct MountPoint *mp, unsigned long mountflags, const void *data) } } if (ret != 0) { - free(mountHdl); + LOSCFG_FS_FREE_HOOK(mountHdl); errno = LittlefsErrno(ret); ret = (int)LOS_NOK; } @@ -239,7 +240,7 @@ int LfsUmount(struct MountPoint *mp) ret = (int)LOS_NOK; } - free(mp->mData); + LOSCFG_FS_FREE_HOOK(mp->mData); mp->mData = NULL; return ret; } @@ -333,7 +334,7 @@ int LfsOpendir(struct Dir *dir, const char *dirName) } lfs_t *lfs = (lfs_t *)dir->dMp->mData; - lfs_dir_t *dirInfo = (lfs_dir_t *)malloc(sizeof(lfs_dir_t)); + lfs_dir_t *dirInfo = (lfs_dir_t *)LOSCFG_FS_MALLOC_HOOK(sizeof(lfs_dir_t)); if (dirInfo == NULL) { errno = ENOMEM; return (int)LOS_NOK; @@ -342,7 +343,7 @@ int LfsOpendir(struct Dir *dir, const char *dirName) (void)memset_s(dirInfo, sizeof(lfs_dir_t), 0, sizeof(lfs_dir_t)); ret = lfs_dir_open(lfs, dirInfo, dirName); if (ret != 0) { - free(dirInfo); + LOSCFG_FS_FREE_HOOK(dirInfo); errno = LittlefsErrno(ret); goto errout; } @@ -421,7 +422,7 @@ int LfsClosedir(struct Dir *dir) ret = (int)LOS_NOK; } - free(dirInfo); + LOSCFG_FS_FREE_HOOK(dirInfo); dir->dData = NULL; return ret; @@ -438,7 +439,7 @@ int LfsOpen(struct File *file, const char *pathName, int openFlag) return (int)LOS_NOK; } - lfsHandle = (lfs_file_t *)malloc(sizeof(lfs_file_t)); + lfsHandle = (lfs_file_t *)LOSCFG_FS_MALLOC_HOOK(sizeof(lfs_file_t)); if (lfsHandle == NULL) { errno = ENOMEM; return (int)LOS_NOK; @@ -447,7 +448,7 @@ int LfsOpen(struct File *file, const char *pathName, int openFlag) int lfsOpenFlag = ConvertFlagToLfsOpenFlag(openFlag); ret = lfs_file_open((lfs_t *)file->fMp->mData, lfsHandle, pathName, lfsOpenFlag); if (ret != 0) { - free(lfsHandle); + LOSCFG_FS_FREE_HOOK(lfsHandle); errno = LittlefsErrno(ret); goto errout; } @@ -575,7 +576,7 @@ int LfsClose(struct File *file) ret = (int)LOS_NOK; } - free(file->fData); + LOSCFG_FS_FREE_HOOK(file->fData); file->fData = NULL; return ret; } diff --git a/components/fs/vfs/los_fs.h b/components/fs/vfs/los_fs.h index 82043dc8..eee83240 100644 --- a/components/fs/vfs/los_fs.h +++ b/components/fs/vfs/los_fs.h @@ -38,6 +38,7 @@ #define _LOS_FS_H_ #include "los_config.h" +#include "los_memory.h" #include "dirent.h" #include "sys/mount.h" #include "sys/statfs.h" @@ -52,6 +53,14 @@ extern "C" { #endif /* __cplusplus */ #endif /* __cplusplus */ +#ifndef LOSCFG_FS_MALLOC_HOOK +#define LOSCFG_FS_MALLOC_HOOK(size) LOS_MemAlloc((VOID *)OS_SYS_MEM_ADDR, size) +#endif + +#ifndef LOSCFG_FS_FREE_HOOK +#define LOSCFG_FS_FREE_HOOK(ptr) LOS_MemFree((VOID *)OS_SYS_MEM_ADDR, ptr) +#endif + int LOS_Open(const char *path, int flags, ...); int LOS_Close(int fd); ssize_t LOS_Read(int fd, void *buff, size_t bytes); diff --git a/components/fs/vfs/vfs_fs.c b/components/fs/vfs/vfs_fs.c index d90a2172..855de691 100644 --- a/components/fs/vfs/vfs_fs.c +++ b/components/fs/vfs/vfs_fs.c @@ -86,7 +86,7 @@ int PollQueryFd(int fd, struct PollTable *table) #endif #define FREE_AND_SET_NULL(ptr) do { \ - free(ptr); \ + LOSCFG_FS_FREE_HOOK(ptr); \ ptr = NULL; \ } while (0) @@ -143,13 +143,13 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz offset = strlen("///") + 1; // three '/' and one '\0' size_t tmpLen = strlen(cwd) + strlen(path) + offset; - char *tmpBuf = (char *)malloc(tmpLen); + char *tmpBuf = (char *)LOSCFG_FS_MALLOC_HOOK(tmpLen); if (tmpBuf == NULL) { return LOS_OK; } if (-1 == sprintf_s(tmpBuf, tmpLen, "/%s/%s/", cwd, path)) { - free(tmpBuf); + LOSCFG_FS_FREE_HOOK(tmpBuf); return LOS_OK; } @@ -158,7 +158,7 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz offset = strlen("/./") - 1; while ((p = strstr(tmpBuf, "/./")) != NULL) { if (EOK != memmove_s(p, tmpLen - (p - tmpBuf), p + offset, tmpLen - (p - tmpBuf) - offset)) { - free(tmpBuf); + LOSCFG_FS_FREE_HOOK(tmpBuf); return LOS_OK; } } @@ -166,7 +166,7 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz /* replace // to / */ while ((p = strstr(tmpBuf, "//")) != NULL) { if (EOK != memmove_s(p, tmpLen - (p - tmpBuf), p + 1, tmpLen - (p - tmpBuf) - 1)) { - free(tmpBuf); + LOSCFG_FS_FREE_HOOK(tmpBuf); return LOS_OK; } } @@ -179,7 +179,7 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz --start; } if (EOK != memmove_s(start, tmpLen - (start - tmpBuf), p + offset, tmpLen - (p - tmpBuf) - offset)) { - free(tmpBuf); + LOSCFG_FS_FREE_HOOK(tmpBuf); return LOS_OK; } } @@ -191,23 +191,24 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz } if ((!buf) || (bufSize == 0)) { - free(tmpBuf); + LOSCFG_FS_FREE_HOOK(tmpBuf); return totalLen; } if (EOK != memcpy_s(buf, bufSize, tmpBuf, (((totalLen + 1) > bufSize) ? bufSize : (totalLen + 1)))) { - free(tmpBuf); + LOSCFG_FS_FREE_HOOK(tmpBuf); return LOS_OK; } buf[bufSize - 1] = 0; - free(tmpBuf); + LOSCFG_FS_FREE_HOOK(tmpBuf); return totalLen; } #endif static int VfsOpen(const char *path, int flags) { + size_t len; struct File *file = NULL; int fd = -1; const char *pathInMp = NULL; @@ -247,13 +248,15 @@ static int VfsOpen(const char *path, int flags) return fd; } - file->fullPath = strdup(path); + len = strlen(path) + 1; + file->fullPath = LOSCFG_FS_MALLOC_HOOK(len); if (file->fullPath == NULL) { VFS_ERRNO_SET(ENOMEM); VfsFilePut(file); VfsUnlock(); return (int)LOS_NOK; } + (void)strcpy_s((char *)file->fullPath, len, path); file->fFlags = (UINT32)flags; file->fOffset = 0; @@ -344,7 +347,7 @@ static int VfsClose(int fd) } if (file->fullPath != NULL) { - free((void *)file->fullPath); + LOSCFG_FS_FREE_HOOK((void *)file->fullPath); } VfsDetachFile(file); @@ -651,7 +654,7 @@ static DIR *VfsOpendir(const char *path) return NULL; } - dir = (struct Dir *)malloc(sizeof(struct Dir)); + dir = (struct Dir *)LOSCFG_FS_MALLOC_HOOK(sizeof(struct Dir)); if (dir == NULL) { VFS_ERRNO_SET(ENOMEM); return NULL; @@ -659,7 +662,7 @@ static DIR *VfsOpendir(const char *path) if (VfsLock() != LOS_OK) { VFS_ERRNO_SET(EAGAIN); - free(dir); + LOSCFG_FS_FREE_HOOK(dir); return NULL; } @@ -667,14 +670,14 @@ static DIR *VfsOpendir(const char *path) if ((mp == NULL) || (pathInMp == NULL)) { VFS_ERRNO_SET(ENOENT); VfsUnlock(); - free(dir); + LOSCFG_FS_FREE_HOOK(dir); return NULL; } if (mp->mFs->fsFops->opendir == NULL) { VFS_ERRNO_SET(ENOTSUP); VfsUnlock(); - free(dir); + LOSCFG_FS_FREE_HOOK(dir); return NULL; } @@ -685,7 +688,7 @@ static DIR *VfsOpendir(const char *path) if (ret == 0) { mp->mRefs++; } else { - free(dir); + LOSCFG_FS_FREE_HOOK(dir); dir = NULL; } @@ -754,7 +757,7 @@ static int VfsClosedir(DIR *d) } VfsUnlock(); - free(dir); + LOSCFG_FS_FREE_HOOK(dir); dir = NULL; return ret; } @@ -927,7 +930,7 @@ int LOS_Open(const char *path, int flags, ...) return (int)LOS_NOK; } - char *canonicalPath = (char *)malloc(pathLen); + char *canonicalPath = (char *)LOSCFG_FS_MALLOC_HOOK(pathLen); if (!canonicalPath) { errno = ENOMEM; return (int)LOS_NOK; @@ -1242,7 +1245,7 @@ ssize_t LOS_Readv(int fd, const struct iovec *iovBuf, int iovcnt) return (ssize_t)LOS_NOK; } totalLen = bufLen * sizeof(char); - buf = (char *)malloc(totalLen); + buf = (char *)LOSCFG_FS_MALLOC_HOOK(totalLen); if (buf == NULL) { return (ssize_t)LOS_NOK; } @@ -1259,7 +1262,7 @@ ssize_t LOS_Readv(int fd, const struct iovec *iovBuf, int iovcnt) size_t lenToRead = totalLen < bytesToRead ? totalLen : bytesToRead; ret = memcpy_s(readBuf, bytesToRead, curBuf, lenToRead); if (ret != EOK) { - free(buf); + LOSCFG_FS_FREE_HOOK(buf); return (ssize_t)LOS_NOK; } if (totalLen < (size_t)bytesToRead) { @@ -1268,7 +1271,7 @@ ssize_t LOS_Readv(int fd, const struct iovec *iovBuf, int iovcnt) curBuf += bytesToRead; totalLen -= bytesToRead; } - free(buf); + LOSCFG_FS_FREE_HOOK(buf); return totalBytesRead; } @@ -1300,7 +1303,7 @@ ssize_t LOS_Writev(int fd, const struct iovec *iovBuf, int iovcnt) return (ssize_t)LOS_NOK; } totalLen = bufLen * sizeof(char); - buf = (char *)malloc(totalLen); + buf = (char *)LOSCFG_FS_MALLOC_HOOK(totalLen); if (buf == NULL) { return (ssize_t)LOS_NOK; } @@ -1313,7 +1316,7 @@ ssize_t LOS_Writev(int fd, const struct iovec *iovBuf, int iovcnt) } ret = memcpy_s(curBuf, totalLen, writeBuf, bytesToWrite); if (ret != EOK) { - free(buf); + LOSCFG_FS_FREE_HOOK(buf); return (ssize_t)LOS_NOK; } curBuf += bytesToWrite; @@ -1321,7 +1324,7 @@ ssize_t LOS_Writev(int fd, const struct iovec *iovBuf, int iovcnt) } totalBytesWritten = write(fd, buf, bufLen); - free(buf); + LOSCFG_FS_FREE_HOOK(buf); return totalBytesWritten; } diff --git a/components/fs/vfs/vfs_maps.c b/components/fs/vfs/vfs_maps.c index 84a15a8e..520c2854 100644 --- a/components/fs/vfs/vfs_maps.c +++ b/components/fs/vfs/vfs_maps.c @@ -33,6 +33,7 @@ #include "securec.h" #include "los_debug.h" #include "los_compiler.h" +#include "los_fs.h" struct FsMap *g_fsMap = NULL; @@ -57,22 +58,25 @@ struct FsMap *VfsFsMapGet(const char *fsType) int OsFsRegister(const char *fsType, struct MountOps *fsMops, struct FileOps *fsFops, struct FsManagement *fsMgt) { + size_t len; if ((fsMops == NULL) || (fsFops == NULL)) { return (int)LOS_NOK; } - struct FsMap *newfs = (struct FsMap *)malloc(sizeof(struct FsMap)); + struct FsMap *newfs = (struct FsMap *)LOSCFG_FS_MALLOC_HOOK(sizeof(struct FsMap)); if (newfs == NULL) { PRINT_ERR("Fs register malloc failed, fsType %s.\n", fsType); return (int)LOS_NOK; } (void)memset_s(newfs, sizeof(struct FsMap), 0, sizeof(struct FsMap)); - newfs->fsType = strdup(fsType); + len = strlen(fsType) + 1; + newfs->fsType = LOSCFG_FS_MALLOC_HOOK(len); if (newfs->fsType == NULL) { - free(newfs); + LOSCFG_FS_FREE_HOOK(newfs); return (int)LOS_NOK; } + (void)strcpy_s((char *)newfs->fsType, len, fsType); newfs->fsMops = fsMops; newfs->fsFops = fsFops; diff --git a/components/fs/vfs/vfs_mount.c b/components/fs/vfs/vfs_mount.c index 737013b7..f9ed3692 100644 --- a/components/fs/vfs/vfs_mount.c +++ b/components/fs/vfs/vfs_mount.c @@ -34,6 +34,7 @@ #include "stdlib.h" #include "string.h" #include "errno.h" +#include "securec.h" #include "vfs_operations.h" #include "los_compiler.h" #include "los_debug.h" @@ -141,7 +142,7 @@ STATIC struct MountPoint *VfsMountPointInit(const char *target, const char *fsTy return NULL; } - mp = (struct MountPoint *)malloc(sizeof(struct MountPoint)); + mp = (struct MountPoint *)LOSCFG_FS_MALLOC_HOOK(sizeof(struct MountPoint)); if (mp == NULL) { return NULL; } @@ -181,6 +182,7 @@ int LOS_FsMount(const char *source, const char *target, const char *fsType, unsigned long mountflags, const void *data) { + size_t len; int ret; struct MountPoint *mp = NULL; @@ -204,18 +206,22 @@ int LOS_FsMount(const char *source, const char *target, } if (source != NULL) { - mp->mDev = strdup(source); + len = strlen(source) + 1; + mp->mDev = LOSCFG_FS_MALLOC_HOOK(len); if (mp->mDev == NULL) { - free(mp); + LOSCFG_FS_FREE_HOOK(mp); VfsUnlock(); return (int)LOS_NOK; } + (void)strcpy_s((char *)mp->mDev, len, source); } - mp->mPath = strdup(target); + len = strlen(target) + 1; + mp->mPath = LOSCFG_FS_MALLOC_HOOK(len); if (mp->mPath == NULL) { goto errout; } + (void)strcpy_s((char *)mp->mPath, len, target); ret = mp->mFs->fsMops->mount(mp, mountflags, data); if (ret != 0) { @@ -229,9 +235,9 @@ int LOS_FsMount(const char *source, const char *target, return LOS_OK; errout: - free((void *)mp->mPath); - free((void *)mp->mDev); - free(mp); + LOSCFG_FS_FREE_HOOK((void *)mp->mPath); + LOSCFG_FS_FREE_HOOK((void *)mp->mDev); + LOSCFG_FS_FREE_HOOK(mp); VfsUnlock(); return (int)LOS_NOK; } @@ -266,9 +272,9 @@ int LOS_FsUmount(const char *target) /* delete mp from mount list */ MpDeleteFromList(mp); mp->mFs->fsRefs--; - free((void *)mp->mPath); - free((void *)mp->mDev); - free(mp); + LOSCFG_FS_FREE_HOOK((void *)mp->mPath); + LOSCFG_FS_FREE_HOOK((void *)mp->mDev); + LOSCFG_FS_FREE_HOOK(mp); VfsUnlock(); return LOS_OK; @@ -326,9 +332,9 @@ int LOS_FsUmount2(const char *target, int flag) /* delete mp from mount list */ MpDeleteFromList(mp); mp->mFs->fsRefs--; - free((void *)mp->mPath); - free((void *)mp->mDev); - free(mp); + LOSCFG_FS_FREE_HOOK((void *)mp->mPath); + LOSCFG_FS_FREE_HOOK((void *)mp->mDev); + LOSCFG_FS_FREE_HOOK(mp); VfsUnlock(); return LOS_OK; diff --git a/components/fs/vfs/vfs_partition.c b/components/fs/vfs/vfs_partition.c index c4c818f7..99d697ab 100644 --- a/components/fs/vfs/vfs_partition.c +++ b/components/fs/vfs/vfs_partition.c @@ -77,6 +77,7 @@ struct DeviceDesc *getDeviceList(VOID) static int AddDevice(const char *dev, const char *fsType, int *lengthArray, int *addrArray, int partNum) { + size_t len; struct DeviceDesc *prev = NULL; for (prev = g_deviceList; prev != NULL; prev = prev->dNext) { if (strcmp(prev->dDev, dev) == 0) { @@ -90,21 +91,25 @@ static int AddDevice(const char *dev, const char *fsType, int *lengthArray, int return (int)LOS_NOK; } - prev = (struct DeviceDesc *)malloc(sizeof(struct DeviceDesc)); + prev = (struct DeviceDesc *)LOSCFG_FS_MALLOC_HOOK(sizeof(struct DeviceDesc)); if (prev == NULL) { errno = -ENOMEM; return (int)LOS_NOK; } - prev->dDev = strdup(dev); - prev->dFsType = strdup(fsType); - prev->dAddrArray = (int *)malloc(partNum * sizeof(int)); + len = strlen(dev) + 1; + prev->dDev = LOSCFG_FS_MALLOC_HOOK(len); + len = strlen(fsType) + 1; + prev->dFsType = LOSCFG_FS_MALLOC_HOOK(len); + prev->dAddrArray = (int *)LOSCFG_FS_MALLOC_HOOK(partNum * sizeof(int)); if (prev->dDev == NULL || prev->dFsType == NULL || prev->dAddrArray == NULL) { goto errout; } + (void)strcpy_s((char *)prev->dDev, len, dev); + (void)strcpy_s((char *)prev->dFsType, len, fsType); (void)memcpy_s(prev->dAddrArray, partNum * sizeof(int), addrArray, partNum * sizeof(int)); if (lengthArray != NULL) { - prev->dLengthArray = (int *)malloc(partNum * sizeof(int)); + prev->dLengthArray = (int *)LOSCFG_FS_MALLOC_HOOK(partNum * sizeof(int)); if (prev->dLengthArray == NULL) { goto errout; } @@ -117,19 +122,19 @@ static int AddDevice(const char *dev, const char *fsType, int *lengthArray, int return LOS_OK; errout: if (prev->dDev != NULL) { - free((void *)prev->dDev); + LOSCFG_FS_FREE_HOOK((void *)prev->dDev); } if (prev->dFsType != NULL) { - free((void *)prev->dFsType); + LOSCFG_FS_FREE_HOOK((void *)prev->dFsType); } if (prev->dAddrArray != NULL) { - free((void *)prev->dAddrArray); + LOSCFG_FS_FREE_HOOK((void *)prev->dAddrArray); } if (prev->dLengthArray != NULL) { - free((void *)prev->dLengthArray); + LOSCFG_FS_FREE_HOOK((void *)prev->dLengthArray); } - free(prev); + LOSCFG_FS_FREE_HOOK(prev); errno = -ENOMEM; return (int)LOS_NOK; }