unity::util::unique_gobject() and friends have ambiguous ownership semantics

Bug #1672657 reported by James Henstridge
This bug affects 1 person
Affects Status Importance Assigned to Milestone
unity-api (Ubuntu)
Fix Released
Pete Woods

Bug Description

The unique_gobject() helper has ownership semantics that are likely to introduce bugs in code using it. It's current logic is essentially:

 1. if the object passed as an argument has a floating reference, increment its ref count.
 2. if not, steal the caller's reference.

So we can't tell statically whether this function steals a reference or creates its own. This makes it more difficult to reason about code using this helper.

It would be better to choose one of the following:

 1. Always create your own reference, using ref_sink() to sink any floating reference.
 2. Always steal the caller's reference. Treat the presence of a floating reference as an
    error, since it indicates that the caller doesn't know if it owns the object.

(1) can be a pain because the caller will need to do a manual unref if they pass a newly constructed object to unique_gobject() that doesn't have a floating reference.

(2) means that the caller will need to do their own ref_sink() call if they are passing an object they don't actually own a reference to.

We picked (2) for thumbnailer's gobj_ptr smart pointer class.

Related branches

Pete Woods (pete-woods)
Changed in unity-api (Ubuntu):
status: New → In Progress
importance: Undecided → Medium
assignee: nobody → Pete Woods (pete-woods)
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package unity-api - 8.6+17.04.20170317-0ubuntu1

unity-api (8.6+17.04.20170317-0ubuntu1) zesty; urgency=medium

  [ Michael Zanetti ]
  * Add appId property to MirSurfaceInterface

  [ Pete Woods ]
  * unity::util - unique_gobject and share_gobject now throw for
    floating references (LP: #1672657)

 -- Lukáš Tinkl <email address hidden> Fri, 17 Mar 2017 11:08:20 +0000

Changed in unity-api (Ubuntu):
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers