Commit 0958ef3f authored by Ramon Nou's avatar Ramon Nou
Browse files

malloc -> calloc mmap

parent 57c1cc66
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -2039,13 +2039,18 @@ gkfs_get_file_list(const std::string& path) {
void*
gkfs_mmap(void* addr, size_t length, int prot, int flags, int fd,
          off_t offset) {
    void* ptr = malloc(length);
    void* ptr = calloc(1, length);
    if(ptr == nullptr) {
        return MAP_FAILED;
    }
    // store info on mmap_set
    mmap_set.insert(std::make_tuple(ptr, fd, length, offset));
    gkfs::syscall::gkfs_pread(fd, ptr, length, offset);
    auto ret = gkfs::syscall::gkfs_pread(fd, ptr, length, offset);
    if(ret == -1) {
        free(ptr);
        mmap_set.erase(std::make_tuple(ptr, fd, length, offset));
        return MAP_FAILED;
    }
    return ptr;
}