0111-Small-cleanups-in-frec_src-datastucture-handling.patch 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. From 6a6e06fbb0d4690507ceaf2bb6f0d8910f3d4914 Mon Sep 17 00:00:00 2001
  2. From: Simon Kelley <simon@thekelleys.org.uk>
  3. Date: Fri, 4 Dec 2020 18:35:11 +0000
  4. Subject: Small cleanups in frec_src datastucture handling.
  5. ---
  6. src/forward.c | 22 +++++++++++++---------
  7. 1 file changed, 13 insertions(+), 9 deletions(-)
  8. --- a/src/forward.c
  9. +++ b/src/forward.c
  10. @@ -353,7 +353,10 @@ static int forward_query(int udpfd, unio
  11. if (!daemon->free_frec_src &&
  12. daemon->frec_src_count < daemon->ftabsize &&
  13. (daemon->free_frec_src = whine_malloc(sizeof(struct frec_src))))
  14. - daemon->frec_src_count++;
  15. + {
  16. + daemon->frec_src_count++;
  17. + daemon->free_frec_src->next = NULL;
  18. + }
  19. /* If we've been spammed with many duplicates, just drop the query. */
  20. if (daemon->free_frec_src)
  21. @@ -390,6 +393,7 @@ static int forward_query(int udpfd, unio
  22. forward->frec_src.orig_id = ntohs(header->id);
  23. forward->frec_src.dest = *dst_addr;
  24. forward->frec_src.iface = dst_iface;
  25. + forward->frec_src.next = NULL;
  26. forward->new_id = get_id();
  27. forward->fd = udpfd;
  28. memcpy(forward->hash, hash, HASH_SIZE);
  29. @@ -2226,16 +2230,16 @@ void free_rfd(struct randfd *rfd)
  30. static void free_frec(struct frec *f)
  31. {
  32. - struct frec_src *src, *tmp;
  33. -
  34. - /* add back to freelist of not the record builtin to every frec. */
  35. - for (src = f->frec_src.next; src; src = tmp)
  36. + struct frec_src *last;
  37. +
  38. + /* add back to freelist if not the record builtin to every frec. */
  39. + for (last = f->frec_src.next; last && last->next; last = last->next) ;
  40. + if (last)
  41. {
  42. - tmp = src->next;
  43. - src->next = daemon->free_frec_src;
  44. - daemon->free_frec_src = src;
  45. + last->next = daemon->free_frec_src;
  46. + daemon->free_frec_src = f->frec_src.next;
  47. }
  48. -
  49. +
  50. f->frec_src.next = NULL;
  51. free_rfd(f->rfd4);
  52. f->rfd4 = NULL;