@@ -2769,10 +2769,6 @@ void mdns_parse_packet(mdns_rx_packet_t * packet)
2769
2769
if (search_result ) {
2770
2770
mdns_txt_item_t * txt = NULL ;
2771
2771
size_t txt_count = 0 ;
2772
- _mdns_result_txt_create (data_ptr , data_len , & txt , & txt_count );
2773
- if (!txt_count ) {
2774
- continue ;
2775
- }
2776
2772
2777
2773
mdns_result_t * result = NULL ;
2778
2774
if (search_result -> type == MDNS_TYPE_PTR ) {
@@ -2792,8 +2788,11 @@ void mdns_parse_packet(mdns_rx_packet_t * packet)
2792
2788
}
2793
2789
}
2794
2790
if (!result -> txt ) {
2795
- result -> txt = txt ;
2796
- result -> txt_count = txt_count ;
2791
+ _mdns_result_txt_create (data_ptr , data_len , & txt , & txt_count );
2792
+ if (txt_count ) {
2793
+ result -> txt = txt ;
2794
+ result -> txt_count = txt_count ;
2795
+ }
2797
2796
}
2798
2797
} else {
2799
2798
_mdns_search_result_add_txt (search_result , txt , txt_count , packet -> tcpip_if , packet -> ip_protocol );
@@ -3305,7 +3304,7 @@ static void _mdns_search_result_add_txt(mdns_search_once_t * search, mdns_txt_it
3305
3304
while (r ) {
3306
3305
if (r -> tcpip_if == tcpip_if && r -> ip_protocol == ip_protocol ) {
3307
3306
if (r -> txt ) {
3308
- return ;
3307
+ goto free_txt ;
3309
3308
}
3310
3309
r -> txt = txt ;
3311
3310
r -> txt_count = txt_count ;
@@ -3316,12 +3315,7 @@ static void _mdns_search_result_add_txt(mdns_search_once_t * search, mdns_txt_it
3316
3315
if (!search -> max_results || search -> num_results < search -> max_results ) {
3317
3316
r = (mdns_result_t * )malloc (sizeof (mdns_result_t ));
3318
3317
if (!r ) {
3319
- for (i = 0 ; i < txt_count ; i ++ ) {
3320
- free ((char * )(txt [i ].key ));
3321
- free ((char * )(txt [i ].value ));
3322
- }
3323
- free (txt );
3324
- return ;
3318
+ goto free_txt ;
3325
3319
}
3326
3320
3327
3321
memset (r , 0 , sizeof (mdns_result_t ));
@@ -3333,6 +3327,14 @@ static void _mdns_search_result_add_txt(mdns_search_once_t * search, mdns_txt_it
3333
3327
search -> result = r ;
3334
3328
search -> num_results ++ ;
3335
3329
}
3330
+ return ;
3331
+
3332
+ free_txt :
3333
+ for (i = 0 ; i < txt_count ; i ++ ) {
3334
+ free ((char * )(txt [i ].key ));
3335
+ free ((char * )(txt [i ].value ));
3336
+ }
3337
+ free (txt );
3336
3338
}
3337
3339
3338
3340
/**
0 commit comments