Skip to content

Commit

Permalink
shm: guard against pool destruction race condition
Browse files Browse the repository at this point in the history
It might happen that a buffer is cached somewhere while the
pool has been set to null after a resize failed
  • Loading branch information
cmeissl committed May 16, 2024
1 parent d763452 commit a6e96ce
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/wayland/shm/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ impl InnerPool {

let pool_guard = self.map.read().unwrap();

// This should not happen, but in case a pool resize failed (which result in a protocol error
// and will kill the client) and the buffer got cached somewhere it is possible that we try to access
// a dead pool.
if pool_guard.ptr.is_null() {
return Err(());
}

trace!(fd = ?self.fd, "Buffer access on shm pool");

// Prepare the access
Expand Down Expand Up @@ -152,6 +159,13 @@ impl InnerPool {

let pool_guard = self.map.write().unwrap();

// This should not happen, but in case a pool resize failed (which result in a protocol error
// and will kill the client) and the buffer got cached somewhere it is possible that we try to access
// a dead pool.
if pool_guard.ptr.is_null() {
return Err(());
}

trace!(fd = ?self.fd, "Mutable buffer access on shm pool");

// Prepare the access
Expand Down

0 comments on commit a6e96ce

Please sign in to comment.