From c61c880fd2de28ed04d1dd137ca6b12b67d18745 Mon Sep 17 00:00:00 2001 From: Erik Boasson Date: Thu, 3 Jan 2019 17:30:25 +0100 Subject: [PATCH] make proxy reader/writer references to sertopics properly counted, strong references without this, deleting the last reader/writer that references the topic results in a dangling pointer ... but there is another intriguing solution: erase the topic from the proxy reader/writer when the last matching local one disappears, so that the topic completely disappears. I rather like this second solution, but I am not yet sure of the consequences and the first (implemented one) is such a simple change that fixes a real problem that it is a no-brainer Signed-off-by: Erik Boasson --- src/core/ddsi/include/ddsi/q_entity.h | 2 +- src/core/ddsi/src/q_entity.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/ddsi/include/ddsi/q_entity.h b/src/core/ddsi/include/ddsi/q_entity.h index 164d56b..488952a 100644 --- a/src/core/ddsi/include/ddsi/q_entity.h +++ b/src/core/ddsi/include/ddsi/q_entity.h @@ -328,7 +328,7 @@ struct proxy_endpoint_common struct proxy_endpoint_common *next_ep; /* next \ endpoint belonging to this proxy participant */ struct proxy_endpoint_common *prev_ep; /* prev / -- this is in arbitrary ordering */ struct nn_xqos *xqos; /* proxy endpoint QoS lives here; FIXME: local ones should have it moved to common as well */ - const struct ddsi_sertopic * topic; /* topic may be NULL: for built-ins, but also for never-yet matched proxies (so we don't have to know the topic; when we match, we certainly do know) */ + struct ddsi_sertopic * topic; /* topic may be NULL: for built-ins, but also for never-yet matched proxies (so we don't have to know the topic; when we match, we certainly do know) */ struct addrset *as; /* address set to use for communicating with this endpoint */ nn_guid_t group_guid; /* 0:0:0:0 if not available */ nn_vendorid_t vendor; /* cached from proxypp->vendor */ diff --git a/src/core/ddsi/src/q_entity.c b/src/core/ddsi/src/q_entity.c index b0638fb..3eca5ff 100644 --- a/src/core/ddsi/src/q_entity.c +++ b/src/core/ddsi/src/q_entity.c @@ -1795,7 +1795,7 @@ static void proxy_writer_add_connection (struct proxy_writer *pwr, struct reader goto already_matched; if (pwr->c.topic == NULL && rd->topic) - pwr->c.topic = rd->topic; + pwr->c.topic = ddsi_sertopic_ref (rd->topic); if (pwr->ddsi2direct_cb == 0 && rd->ddsi2direct_cb != 0) { pwr->ddsi2direct_cb = rd->ddsi2direct_cb; @@ -1910,7 +1910,7 @@ static void proxy_reader_add_connection (struct proxy_reader *prd, struct writer m->wr_guid = wr->e.guid; os_mutexLock (&prd->e.lock); if (prd->c.topic == NULL) - prd->c.topic = wr->topic; + prd->c.topic = ddsi_sertopic_ref (wr->topic); if (ut_avlLookupIPath (&prd_writers_treedef, &prd->writers, &wr->e.guid, &path)) { DDS_LOG(DDS_LC_DISCOVERY, " proxy_reader_add_connection(wr %x:%x:%x:%x prd %x:%x:%x:%x) - already connected\n", @@ -4055,6 +4055,7 @@ static void proxy_endpoint_common_fini (struct entity_common *e, struct proxy_en { unref_proxy_participant (c->proxypp, c); + ddsi_sertopic_unref (c->topic); nn_xqos_fini (c->xqos); os_free (c->xqos); unref_addrset (c->as);