Fix the Preferences crash: a RefCell borrow held across the match
This commit is contained in:
2 files changed
+25
-1
No files matched your search
@@ -226,6 +226,25 @@ check $? "clicking the notification activates app.focus"
|
||||
grep -q 'regent: bringing the window to the front' "$TMP_HOME/app.log"
|
||||
check $? "clicking the notification brings the window to the front"
|
||||
|
||||
printf '\n== the app actions ==\n'
|
||||
# Preferences builds its dialog on the first activation and re-presents it on the
|
||||
# second; both reach their window through the registry, not app.windows(). A
|
||||
# `RefCell` borrow held across the build (or the wrong window) shows up here as a
|
||||
# dead process rather than as a silent misbehaviour.
|
||||
OBJ_PATH="/$(printf '%s' "$DATA_DIR" | tr '.' '/')"
|
||||
for action in preferences preferences identities; do
|
||||
gdbus call --session --dest "$DATA_DIR" --object-path "$OBJ_PATH" \
|
||||
--method org.freedesktop.Application.ActivateAction "$action" '[]' '{}' \
|
||||
>/dev/null 2>&1
|
||||
sleep 1
|
||||
done
|
||||
|
||||
kill -0 "$APP" 2>/dev/null
|
||||
check $? "activating Preferences twice and Identities leaves the app running"
|
||||
|
||||
! grep -q 'panicked' "$TMP_HOME/app.log"
|
||||
check $? "and nothing panicked"
|
||||
|
||||
# The GUI owns the D-Bus name; headless must not run alongside it, and we need
|
||||
# it gone so the two do not race over apps.json.
|
||||
kill "$APP" 2>/dev/null
|
||||
|
||||
+6
-1
@@ -100,7 +100,12 @@ impl Windows {
|
||||
/// and its listeners must stay registered because the lock state changes
|
||||
/// while it is open.
|
||||
pub fn present_preferences(&self) {
|
||||
let preferences = match self.preferences.borrow().clone() {
|
||||
// Bind the clone to a local first: a `match` scrutinee is a temporary
|
||||
// scope that lasts to the end of the match, so `borrow()`ing inline would
|
||||
// still hold the `Ref` when the `None` arm takes `borrow_mut()` — and
|
||||
// panic with "RefCell already borrowed".
|
||||
let existing = self.preferences.borrow().clone();
|
||||
let preferences = match existing {
|
||||
Some(preferences) => preferences,
|
||||
None => {
|
||||
let preferences = Preferences::new(Rc::clone(&self.state));
|
||||
|
||||
Reference in new issue
Block a user