@@ -2738,10 +2738,17 @@ static bool _hostname_is_ours(const char * hostname)
2738
2738
return false;
2739
2739
}
2740
2740
2741
+ /**
2742
+ * @brief Adds a delegated hostname to the linked list
2743
+ * @param hostname Host name pointer
2744
+ * @param address_list Address list
2745
+ * @return true on success
2746
+ * false if the host wasn't attached (this is our hostname, or alloc failure) so we have to free the structs
2747
+ */
2741
2748
static bool _mdns_delegate_hostname_add (const char * hostname , mdns_ip_addr_t * address_list )
2742
2749
{
2743
2750
if (_hostname_is_ours (hostname )) {
2744
- return true ;
2751
+ return false ;
2745
2752
}
2746
2753
2747
2754
mdns_host_item_t * host = (mdns_host_item_t * )malloc (sizeof (mdns_host_item_t ));
@@ -2789,6 +2796,18 @@ static mdns_ip_addr_t * copy_address_list(const mdns_ip_addr_t * address_list)
2789
2796
return head ;
2790
2797
}
2791
2798
2799
+ static void free_delegated_hostnames (void )
2800
+ {
2801
+ mdns_host_item_t * host = _mdns_host_list ;
2802
+ while (host != NULL ) {
2803
+ free_address_list (host -> address_list );
2804
+ free ((char * )host -> hostname );
2805
+ mdns_host_item_t * item = host ;
2806
+ host = host -> next ;
2807
+ free (item );
2808
+ }
2809
+ }
2810
+
2792
2811
static bool _mdns_delegate_hostname_remove (const char * hostname )
2793
2812
{
2794
2813
mdns_srv_item_t * srv = _mdns_server -> services ;
@@ -4657,8 +4676,11 @@ static void _mdns_execute_action(mdns_action_t * action)
4657
4676
_mdns_packet_free (action -> data .rx_handle .packet );
4658
4677
break ;
4659
4678
case ACTION_DELEGATE_HOSTNAME_ADD :
4660
- _mdns_delegate_hostname_add (action -> data .delegate_hostname .hostname ,
4661
- action -> data .delegate_hostname .address_list );
4679
+ if (!_mdns_delegate_hostname_add (action -> data .delegate_hostname .hostname ,
4680
+ action -> data .delegate_hostname .address_list )) {
4681
+ free ((char * )action -> data .delegate_hostname .hostname );
4682
+ free_address_list (action -> data .delegate_hostname .address_list );
4683
+ }
4662
4684
break ;
4663
4685
case ACTION_DELEGATE_HOSTNAME_REMOVE :
4664
4686
_mdns_delegate_hostname_remove (action -> data .delegate_hostname .hostname );
@@ -5008,6 +5030,7 @@ void mdns_free(void)
5008
5030
#endif
5009
5031
5010
5032
mdns_service_remove_all ();
5033
+ free_delegated_hostnames ();
5011
5034
_mdns_service_task_stop ();
5012
5035
for (i = 0 ; i < MDNS_IF_MAX ; i ++ ) {
5013
5036
for (j = 0 ; j < MDNS_IP_PROTOCOL_MAX ; j ++ ) {
0 commit comments