From 6dacb4e1b039d265d227f64c1385a2c584e01964 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Mon, 14 Aug 2023 23:39:14 +0300 Subject: [PATCH] Feedback --- libudpard/udpard.c | 16 +++++++++------- libudpard/udpard.h | 6 +++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/libudpard/udpard.c b/libudpard/udpard.c index 5d93152..6aea455 100644 --- a/libudpard/udpard.c +++ b/libudpard/udpard.c @@ -1698,23 +1698,25 @@ int_fast8_t udpardRxSubscriptionReceive(struct UdpardRxSubscription* const self, const uint_fast8_t redundant_iface_index, struct UdpardRxTransfer* const out_transfer) { - bool release = true; - int_fast8_t result = -UDPARD_ERROR_ARGUMENT; + int_fast8_t result = -UDPARD_ERROR_ARGUMENT; if ((self != NULL) && (timestamp_usec != TIMESTAMP_UNSET) && (datagram_payload.data != NULL) && (redundant_iface_index < UDPARD_NETWORK_INTERFACE_COUNT_MAX) && (out_transfer != NULL)) { - result = rxPortAcceptFrame(&self->port, + result = rxPortAcceptFrame(&self->port, redundant_iface_index, timestamp_usec, datagram_payload, self->memory, out_transfer); - release = false; } - if ((self != NULL) && release) + else if (self != NULL) { memFreePayload(self->memory.payload, datagram_payload); } + else + { + (void) 0; + } return result; } @@ -1827,13 +1829,13 @@ int_fast8_t udpardRxRPCDispatcherReceive(struct UdpardRxRPCDispatcher* const sel self->memory, &out_transfer->base); release = false; - } + } // else, the application is not interested in this service-ID (does not know how to handle it). // Expose the port instance to the caller if requested. if (out_port != NULL) { *out_port = item; } - } + } // else, we didn't accept so we just ignore this frame } if ((self != NULL) && release) { diff --git a/libudpard/udpard.h b/libudpard/udpard.h index 7bf88b9..1b22a10 100644 --- a/libudpard/udpard.h +++ b/libudpard/udpard.h @@ -844,7 +844,9 @@ void udpardRxSubscriptionFree(struct UdpardRxSubscription* const self); /// fragment of the reassembled transfer payload or free it using the corresponding memory resource /// (see UdpardRxMemoryResources) if the datagram is not needed for reassembly. Because of the ownership transfer, /// the datagram payload buffer has to be mutable (non-const). -/// In the case of an invalid argument error the library will attempt to free the datagram payload buffer. +/// One exception is that if the "self" pointer is invalid, the library will be unable to process or free the datagram, +/// which may lead to a memory leak in the application; hence, the caller should always check that the "self" pointer +/// is always valid. /// /// The accepted datagram may either be invalid, carry a non-final part of a multi-frame transfer, /// carry a final part of a valid multi-frame transfer, or carry a valid single-frame transfer. @@ -1021,6 +1023,8 @@ int_fast8_t udpardRxRPCDispatcherCancel(struct UdpardRxRPCDispatcher* const self /// It is the analog of udpardRxSubscriptionReceive for RPC-service transfers. /// Please refer to the documentation of udpardRxSubscriptionReceive for the usage information. /// +/// Frames (datagrams) that belong to transfers for which there is no active RX RPC port are ignored. +/// /// The "out_port" pointer-to-pointer can be used to retrieve the specific UdpardRxRPCPort instance that was used to /// process the received transfer. Remember that each UdpardRxRPCPort instance has a user reference field, /// which in combination with this feature can be used to construct OOP interfaces on top of the library.