From 7e877be8fb34ab99421a2eaf3d8fb1b96ed95206 Mon Sep 17 00:00:00 2001 From: cheliequan <liequanche@126.com> Date: 星期四, 08 十二月 2022 21:06:52 +0800 Subject: [PATCH] 增加共享内存hash链表操作 --- src/memfd.c | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/memfd.c b/src/memfd.c index 04ced4d..2509685 100644 --- a/src/memfd.c +++ b/src/memfd.c @@ -70,12 +70,16 @@ struct stat st; /* Create an anonymous file in tmpfs; */ + if(0 >= len) + { + return -1; + } fd = sys_memfd_create(name, MFD_CLOEXEC); if (fd == -1) { - errExit("memfd_create"); + errExit("memfd_create"); } /* Size the file as specified on the command line */ @@ -83,7 +87,7 @@ mydebug("length: %zu\n", len); if (ftruncate(fd, len) == -1) { - errExit("truncate"); + errExit("ftruncate"); } if (fstat (fd, &st)) @@ -174,12 +178,12 @@ } len = st.st_size; - ret = munmap(*ppaddr, len); + ret = munmap((void *)*ppaddr, len); if (ret == -1) { errExit("munmap()"); } - + *ppaddr = NULL; mydebug("length: %zu, atime: %lu.%lu\n", len, st.st_atim.tv_sec, st.st_atim.tv_nsec); return len; } -- Gitblit v1.8.0