Commit ea6862d4 authored by Julius Athenstaedt's avatar Julius Athenstaedt
Browse files

fix fill_fuse_entry_param racecondition by gemini

parent b42e4bad
Loading
Loading
Loading
Loading
Loading
+18 −8
Original line number Diff line number Diff line
@@ -112,17 +112,27 @@ fill_fuse_entry_param(const u_data* ud, const std::string path,
        return rc;
    }

    // See if we already have this path
    ino_mutex.lock();
    auto it_end = path_map.end();
    auto it = check_path_map ? path_map.find(path) : it_end;
    ino_mutex.unlock();
    fuse_ino_t ino = 0;
    bool found = false;

    fuse_ino_t ino;
    if(it != it_end) {
    // CRITICAL SECTION
    {
        std::lock_guard<std::mutex> lk(ino_mutex);
        if(check_path_map) {
            auto it = path_map.find(path);
            if(it != path_map.end()) {
                ino = it->second;
                found = true;
            }
        }
    } // Lock releases here

    if(found) {
        auto inode = get_inode(ino);
        if(inode) {
            // Note: This increment is technically racy (read-modify-write)
            // because get_inode returns a raw pointer and doesn't lock the
            // inode itself. But the SEGFAULT comes from the map iterator above.
            inode->lookup_count++;
        }
    } else {