From 98f757a5ab995e7c45e2de937d1281a5b8ceac9b Mon Sep 17 00:00:00 2001 From: Erik Boasson Date: Thu, 17 Jan 2019 12:34:37 +0100 Subject: [PATCH] let dds_get_qos reset the input qos first Getting a QoS from an entity is akin to reading, and all read/take operations reuse or free/reallocate memory to avoid memory leaks, and so it is a reasonable assumption that calling dds_get_qos repeatedly without intervening calls to dds_reset_qos would not leak any memory either. (This was actually an assumption in the builtin topics test.) Therefore, it is reasonable to first call dds_reset_qos in dds_get_qos. All operations in the API that yield or modify a QoS object result in a properly initialised one, therefore the input to dds_get_qos is necessarily initialised, and so this is safe. Signed-off-by: Erik Boasson --- src/core/ddsc/src/dds_entity.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/ddsc/src/dds_entity.c b/src/core/ddsc/src/dds_entity.c index 90097c8..7781875 100644 --- a/src/core/ddsc/src/dds_entity.c +++ b/src/core/ddsc/src/dds_entity.c @@ -363,10 +363,13 @@ dds_return_t dds_get_qos (dds_entity_t entity, dds_qos_t *qos) if ((rc = dds_entity_lock (entity, DDS_KIND_DONTCARE, &e)) != DDS_RETCODE_OK) return DDS_ERRNO (rc); - if (e->m_deriver.set_qos) - ret = dds_copy_qos (qos, e->m_qos); - else + if (e->m_deriver.set_qos == 0) ret = DDS_ERRNO(DDS_RETCODE_ILLEGAL_OPERATION); + else + { + dds_reset_qos (qos); + ret = dds_copy_qos (qos, e->m_qos); + } dds_entity_unlock(e); return ret; }