File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -557,7 +557,8 @@ int dns_packet_append_name(
557
557
bool canonical_candidate ,
558
558
size_t * start ) {
559
559
560
- size_t saved_size ;
560
+ _cleanup_free_ char * * added_entries = NULL ; /* doesn't own the strings! this is just regular pointer array, not a NULL-terminated strv! */
561
+ size_t n_added_entries = 0 , saved_size ;
561
562
int r ;
562
563
563
564
assert (p );
@@ -598,6 +599,11 @@ int dns_packet_append_name(
598
599
if (allow_compression ) {
599
600
_cleanup_free_ char * s = NULL ;
600
601
602
+ if (!GREEDY_REALLOC (added_entries , n_added_entries + 1 )) {
603
+ r = - ENOMEM ;
604
+ goto fail ;
605
+ }
606
+
601
607
s = strdup (z );
602
608
if (!s ) {
603
609
r = - ENOMEM ;
@@ -608,7 +614,8 @@ int dns_packet_append_name(
608
614
if (r < 0 )
609
615
goto fail ;
610
616
611
- TAKE_PTR (s );
617
+ /* Keep track of the entries we just added (note that the string is owned by the hashtable, not this array!) */
618
+ added_entries [n_added_entries ++ ] = TAKE_PTR (s );
612
619
}
613
620
}
614
621
@@ -623,6 +630,12 @@ int dns_packet_append_name(
623
630
return 0 ;
624
631
625
632
fail :
633
+ /* Remove all label compression names we added again */
634
+ FOREACH_ARRAY (s , added_entries , n_added_entries ) {
635
+ hashmap_remove (p -> names , * s );
636
+ free (* s );
637
+ }
638
+
626
639
dns_packet_truncate (p , saved_size );
627
640
return r ;
628
641
}
You can’t perform that action at this time.
0 commit comments