Skip to content

Commit

Permalink
Merge branch 'destruction-guards'
Browse files Browse the repository at this point in the history
* destruction-guards:
  BST: bsttreestores: guard against stale notifications from destroyed proxies
  BST: guard against method calls on orphan proxy (happens during destruction)
  BSE: TrackImpl: get_output_source: guard against NULL result
  BSE: guard against calling bse_song_ensure_master on NULL
  BSE: ProjectImpl: add a few paranoid NULL result guards
  BSE: ItemImpl: common_ancestor(): guard against NULL result
  BSE: ContainerImpl: guard lookup_item() and get_item() against NULL returns
  BSE: SongImpl::find_any_track_for_part: guard against NULL results

Signed-off-by: Tim Janik <[email protected]>
  • Loading branch information
tim-janik committed Mar 8, 2018
2 parents bbb360f + d457645 commit ba21e19
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 32 deletions.
6 changes: 4 additions & 2 deletions beast-gtk/bstitemview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,9 @@ bst_item_view_select (BstItemView *self,
assert_return (BST_IS_ITEM_VIEW (self));
assert_return (BSE_IS_ITEM (itemid));
Bse::ItemH item = Bse::ItemH::down_cast (bse_server.from_proxy (itemid));
Bse::ItemH parent = item ? item.get_parent() : Bse::ItemH();

if (self->tree && item.get_parent().proxy_id() == self->container)
if (self->tree && parent && parent.proxy_id() == self->container)
{
GtkTreeIter witer;
if (bst_child_list_wrapper_get_iter (self->wlist, &witer, itemid))
Expand All @@ -296,8 +297,9 @@ bst_item_view_get_proxy_row (BstItemView *self,
assert_return (BST_IS_ITEM_VIEW (self), -1);
assert_return (BSE_IS_ITEM (itemid), -1);
Bse::ItemH item = Bse::ItemH::down_cast (bse_server.from_proxy (itemid));
Bse::ItemH parent = item ? item.get_parent() : Bse::ItemH();

if (self->tree && item.get_parent().proxy_id() == self->container)
if (self->tree && parent && parent.proxy_id() == self->container)
{
GtkTreeIter witer;
if (bst_child_list_wrapper_get_iter (self->wlist, &witer, itemid))
Expand Down
45 changes: 24 additions & 21 deletions beast-gtk/bsttreestores.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ typedef struct _ProxyStore ProxyStore;
struct _ProxyStore
{
GxkListWrapper *self;
gint (*row_from_proxy) (ProxyStore *ps, SfiProxy proxy);
int (*row_from_proxy) (ProxyStore *ps, SfiProxy proxy);
union {
struct {
SfiUPool *ipool;
Expand All @@ -203,7 +203,7 @@ proxy_store_item_property_notify (SfiProxy item,
const gchar *property_name,
ProxyStore *ps)
{
gint row = ps->row_from_proxy (ps, item);
int row = ps->row_from_proxy (ps, item);
if (row >= 0) /* the item can be removed already */
gxk_list_wrapper_notify_change (ps->self, row);
}
Expand All @@ -212,7 +212,8 @@ static gint
proxy_store_item_listen_on (ProxyStore *ps,
SfiProxy item)
{
gint row = ps->row_from_proxy (ps, item);
int row = ps->row_from_proxy (ps, item);
assert_return (row >= 0, row);
bse_proxy_connect (item,
"signal::property-notify::seqid", proxy_store_item_property_notify, ps,
"signal::property-notify::uname", proxy_store_item_property_notify, ps,
Expand All @@ -239,11 +240,14 @@ proxy_store_get_iter (ProxyStore *ps,
GtkTreeIter *iter,
SfiProxy item)
{
gboolean isset = FALSE;
gint row = ps->row_from_proxy (ps, item);
GtkTreePath *path = gtk_tree_path_new_from_indices (row, -1);
isset = row >= 0 && gtk_tree_model_get_iter (GTK_TREE_MODEL (ps->self), iter, path);
gtk_tree_path_free (path);
bool isset = false;
int row = ps->row_from_proxy (ps, item);
if (row >= 0)
{
GtkTreePath *path = gtk_tree_path_new_from_indices (row, -1);
isset = row >= 0 && gtk_tree_model_get_iter (GTK_TREE_MODEL (ps->self), iter, path);
gtk_tree_path_free (path);
}
return isset;
}

Expand Down Expand Up @@ -291,7 +295,7 @@ static gint
child_list_wrapper_row_from_proxy (ProxyStore *ps, SfiProxy proxy)
{
Bse::ItemH item = Bse::ItemH::down_cast (bse_server.from_proxy (proxy));
return item.get_seqid() - 1;
return int (item ? item.get_seqid() : 0) - 1;
}

static gboolean
Expand Down Expand Up @@ -393,7 +397,9 @@ bst_child_list_wrapper_get_proxy (GxkListWrapper *self,
{
guint seqid = row + 1;
Bse::ContainerH container = Bse::ContainerH::down_cast (bse_server.from_proxy (ps->u.cl.container));
Bse::ItemH item = container.get_item (ps->u.cl.child_type, seqid);
Bse::ItemH item;
if (container)
item = container.get_item (ps->u.cl.child_type, seqid);
return item ? item.proxy_id() : 0;
}
return 0;
Expand All @@ -413,7 +419,7 @@ bst_child_list_wrapper_proxy_changed (GxkListWrapper *self,
SfiProxy item)
{
ProxyStore *ps = (ProxyStore*) g_object_get_data ((GObject*) self, "ProxyStore");
gint row = ps->row_from_proxy (ps, item);
int row = ps->row_from_proxy (ps, item);
if (row >= 0)
gxk_list_wrapper_notify_change (ps->self, row);
}
Expand Down Expand Up @@ -613,12 +619,9 @@ bst_item_seq_store_remove (GtkTreeModel *model,
SfiProxy proxy)
{
ProxyStore *ps = (ProxyStore*) g_object_get_data ((GObject*) model, "ProxyStore");
gint row = item_seq_store_row_from_proxy (ps, proxy);
if (row >= 0)
{
ps->u.pq.items = sfi_ring_remove (ps->u.pq.items, (gpointer) proxy);
proxy_store_item_unlisten_on (ps, proxy, row);
}
int row = item_seq_store_row_from_proxy (ps, proxy);
ps->u.pq.items = sfi_ring_remove (ps->u.pq.items, (gpointer) proxy);
proxy_store_item_unlisten_on (ps, proxy, row);
return row;
}

Expand All @@ -627,7 +630,7 @@ bst_item_seq_store_can_raise (GtkTreeModel *model,
SfiProxy proxy)
{
ProxyStore *ps = (ProxyStore*) g_object_get_data ((GObject*) model, "ProxyStore");
gint row = item_seq_store_row_from_proxy (ps, proxy);
int row = item_seq_store_row_from_proxy (ps, proxy);
return row > 0;
}

Expand All @@ -636,7 +639,7 @@ bst_item_seq_store_raise (GtkTreeModel *model,
SfiProxy proxy)
{
ProxyStore *ps = (ProxyStore*) g_object_get_data ((GObject*) model, "ProxyStore");
gint row = item_seq_store_row_from_proxy (ps, proxy);
int row = item_seq_store_row_from_proxy (ps, proxy);
if (row > 0)
{
ps->u.pq.items = sfi_ring_remove (ps->u.pq.items, (gpointer) proxy);
Expand All @@ -653,7 +656,7 @@ bst_item_seq_store_can_lower (GtkTreeModel *model,
SfiProxy proxy)
{
ProxyStore *ps = (ProxyStore*) g_object_get_data ((GObject*) model, "ProxyStore");
gint row = item_seq_store_row_from_proxy (ps, proxy);
int row = item_seq_store_row_from_proxy (ps, proxy);
return row >= 0 && sfi_ring_tail (ps->u.pq.items)->data != (gpointer) proxy;
}

Expand All @@ -662,7 +665,7 @@ bst_item_seq_store_lower (GtkTreeModel *model,
SfiProxy proxy)
{
ProxyStore *ps = (ProxyStore*) g_object_get_data ((GObject*) model, "ProxyStore");
gint row = item_seq_store_row_from_proxy (ps, proxy);
int row = item_seq_store_row_from_proxy (ps, proxy);
if (row >= 0 && sfi_ring_tail (ps->u.pq.items)->data != (gpointer) proxy)
{
ps->u.pq.items = sfi_ring_remove (ps->u.pq.items, (gpointer) proxy);
Expand Down
4 changes: 2 additions & 2 deletions bse/bsecontainer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ ContainerImpl::lookup_item (const String &uname)
{
BseContainer *self = as<BseContainer*>();
BseItem *child = bse_container_lookup_item (self, uname.c_str());
return child->as<ItemIfaceP>();
return child ? child->as<ItemIfaceP>() : NULL;
}

ItemIfaceP
Expand All @@ -1334,7 +1334,7 @@ ContainerImpl::get_item (const String &item_type, int seq_id)
BseContainer *self = as<BseContainer*>();
GType type = g_type_from_name (item_type.c_str());
BseItem *child = bse_container_get_item (self, type, seq_id);
return child->as<ItemIfaceP>();
return child ? child->as<ItemIfaceP>() : NULL;
}

static gboolean
Expand Down
2 changes: 1 addition & 1 deletion bse/bseitem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,7 @@ ItemImpl::common_ancestor (ItemIface &other)
BseItem *self = as<BseItem*>();
BseItem *bo = other.as<BseItem*>();
BseItem *common = bse_item_common_ancestor (self, bo);
return common->as<ItemIfaceP>();
return common ? common->as<ItemIfaceP>() : NULL;
}

bool
Expand Down
6 changes: 3 additions & 3 deletions bse/bseproject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ ProjectImpl::create_song (const String &name)
push_undo (__func__, *this, remove_song_lambda);
}
bse_item_undo_close (ustack);
return song->as<SongIfaceP>();
return song ? song->as<SongIfaceP>() : NULL;
}

CSynthIfaceP
Expand All @@ -1295,7 +1295,7 @@ ProjectImpl::create_csynth (const String &name)
push_undo (__func__, *this, remove_csynth_lambda);
}
bse_item_undo_close (ustack);
return csynth->as<CSynthIfaceP>();
return csynth ? csynth->as<CSynthIfaceP>() : NULL;
}

MidiSynthIfaceP
Expand All @@ -1317,7 +1317,7 @@ ProjectImpl::create_midi_synth (const String &name)
push_undo (__func__, *this, remove_midi_synth_lambda);
}
bse_item_undo_close (ustack);
return midi_synth->as<MidiSynthIfaceP>();
return midi_synth ? midi_synth->as<MidiSynthIfaceP>() : NULL;
}

WaveRepoIfaceP
Expand Down
3 changes: 2 additions & 1 deletion bse/bsesong.cc
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ master_bus_name (void)
BseSource*
bse_song_ensure_master (BseSong *self)
{
assert_return (BSE_IS_SONG (self), NULL);
Bse::SongImpl *this_ = self->as<Bse::SongImpl*>();
BseSource *child = (BseSource*) bse_song_find_master (self);
if (!child)
Expand Down Expand Up @@ -775,7 +776,7 @@ SongImpl::find_any_track_for_part (PartIface &part)
assert_return (dynamic_cast<ItemImpl*> (&part)->parent() == this, NULL);
BsePart *bpart = part.as<BsePart*>();
BseTrack *track = bse_song_find_first_track (self, bpart);
return track->as<TrackIfaceP> ();
return track ? track->as<TrackIfaceP> () : NULL;
}

BusIfaceP
Expand Down
3 changes: 1 addition & 2 deletions bse/bsetrack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1277,8 +1277,7 @@ TrackImpl::get_output_source ()
{
BseTrack *self = as<BseTrack*>();
BseSource *child = bse_track_get_output (self);
return child->as<SourceIfaceP>();
return child->as<SourceIfaceP>();
return child ? child->as<SourceIfaceP>() : NULL;
}

ItemSeq
Expand Down

0 comments on commit ba21e19

Please sign in to comment.