D15574: Avoid undefined behavior due to dangling file descriptor

Tobias Deiminger noreply at phabricator.kde.org
Mon Sep 17 13:32:18 BST 2018


tobiasdeiminger created this revision.
Herald added a project: Okular.
Herald added a subscriber: okular-devel.
tobiasdeiminger requested review of this revision.

REVISION SUMMARY
  We request a inhibit lock of DBus type UNIX_FD from systemd logind. It's wrapped into (and owned by) a QDBusUnixFileDescriptor object of automatic storage. The file descriptor will be closed in QDBusUnixFileDescriptor Dtor, and may be reused by some other facility (e.g. pulseaudio).
  
  If we want to store the lock longer than QDBusUnixFileDescriptor lifetime, we have to dup the file descriptor. If we don't dup, and close the original fd later in PresentationWidget::allowPowerManagement, bad things may happen.
  
  Besides that, what we get from systemd is really a file descriptor, not a "cookie". So I renamed the m_sleepInhibitCookie to m_sleepInhibitFd and changed initial state to -1 accordingly.
  
  BUG 393478
  BUG 398720

TEST PLAN
  - bugs don't occur any longer
  - inhibiting sleep during presentation mode still works

REPOSITORY
  R223 Okular

BRANCH
  fix_dbus_fd

REVISION DETAIL
  https://phabricator.kde.org/D15574

AFFECTED FILES
  ui/presentationwidget.cpp
  ui/presentationwidget.h

To: tobiasdeiminger
Cc: okular-devel, ngraham, aacid
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/okular-devel/attachments/20180917/44f60d19/attachment.html>


More information about the Okular-devel mailing list