Let's drop meaningless optimization, and always check if the window is
owned by the expected fd.
-static bool window_matches(Window *w, uint64_t offset, size_t size) {
- assert(w);
+static bool window_matches(Window *w, MMapFileDescriptor *f, uint64_t offset, size_t size) {
offset >= w->offset &&
offset + size <= w->offset + w->size;
}
offset >= w->offset &&
offset + size <= w->offset + w->size;
}
-static bool window_matches_fd(Window *w, MMapFileDescriptor *f, uint64_t offset, size_t size) {
- assert(w);
- assert(f);
-
- return
- w->fd == f &&
- window_matches(w, offset, size);
-}
-
static Window *window_add(MMapCache *m, MMapFileDescriptor *f, bool keep_always, uint64_t offset, size_t size, void *ptr) {
Window *w;
static Window *window_add(MMapCache *m, MMapFileDescriptor *f, bool keep_always, uint64_t offset, size_t size, void *ptr) {
Window *w;
if (!c->window)
return 0;
if (!c->window)
return 0;
- if (!window_matches_fd(c->window, f, offset, size)) {
+ if (!window_matches(c->window, f, offset, size)) {
/* Drop the reference to the window, since it's unnecessary now */
context_detach_window(f->cache, c);
/* Drop the reference to the window, since it's unnecessary now */
context_detach_window(f->cache, c);
return -EIO;
LIST_FOREACH(by_fd, w, f->windows)
return -EIO;
LIST_FOREACH(by_fd, w, f->windows)
- if (window_matches(w, offset, size)) {
+ if (window_matches(w, f, offset, size)) {