@@ -140,7 +140,10 @@ static inline void memFree(const struct UdpardMemoryResource memory, const size_
140140static inline void memFreePayload (const struct UdpardMemoryDeleter memory , const struct UdpardMutablePayload payload )
141141{
142142 UDPARD_ASSERT (memory .deallocate != NULL );
143- memory .deallocate (memory .user_reference , payload .size , payload .data );
143+ if (payload .data != NULL )
144+ {
145+ memory .deallocate (memory .user_reference , payload .size , payload .data );
146+ }
144147}
145148
146149static inline void memZero (const size_t size , void * const data )
@@ -1081,13 +1084,18 @@ static inline bool rxSlotEject(size_t* const out_payload_size,
10811084 {
10821085 result = true;
10831086 * out_payload_size = eject_ctx .retain_size ;
1084- * out_payload_head = (eject_ctx .head != NULL )
1085- ? (* eject_ctx .head ) // Slice off the derived type fields as they are not needed.
1086- : (struct UdpardFragment ){.next = NULL , .view = {0 , NULL }, .origin = {0 , NULL }};
1087- // This is the single-frame transfer optimization suggested by Scott: we free the first fragment handle
1088- // early by moving the contents into the rx_transfer structure by value.
1089- // No need to free the payload buffer because it has been transferred to the transfer.
1090- memFree (memory .fragment , sizeof (RxFragment ), eject_ctx .head ); // May be empty.
1087+ if (eject_ctx .head != NULL )
1088+ {
1089+ // This is the single-frame transfer optimization suggested by Scott: we free the first fragment handle
1090+ // early by moving the contents into the rx_transfer structure by value.
1091+ // No need to free the payload buffer because it has been transferred to the transfer.
1092+ * out_payload_head = * eject_ctx .head ; // Slice off the derived type fields as they are not needed.
1093+ memFree (memory .fragment , sizeof (RxFragment ), eject_ctx .head );
1094+ }
1095+ else
1096+ {
1097+ * out_payload_head = (struct UdpardFragment ){.next = NULL , .view = {0 , NULL }, .origin = {0 , NULL }};
1098+ }
10911099 }
10921100 else // The transfer turned out to be invalid. We have to free the fragments. Can't use the tree anymore.
10931101 {
0 commit comments