77 lines
2.3 KiB

  1. commit d28afe3631e20a9fcca47efde031d62e501eff48
  2. Author: Willy Tarreau <w@1wt.eu>
  3. Date: Mon Oct 15 11:18:03 2018 +0200
  4. BUILD: peers: check allocation error during peers_init_sync()
  5. peers_init_sync() doesn't check task_new()'s return value and doesn't
  6. return any result to indicate success or failure. Let's make it return
  7. an int and check it from the caller.
  8. This can be backported as far as 1.6.
  9. (cherry picked from commit d944344f01d9ea914d94c45f6ac7c224c6143fc9)
  10. Signed-off-by: Willy Tarreau <w@1wt.eu>
  11. diff --git a/include/proto/peers.h b/include/proto/peers.h
  12. index 782b66e4..9d4aaff2 100644
  13. --- a/include/proto/peers.h
  14. +++ b/include/proto/peers.h
  15. @@ -28,7 +28,7 @@
  16. #include <types/stream.h>
  17. #include <types/peers.h>
  18. -void peers_init_sync(struct peers *peers);
  19. +int peers_init_sync(struct peers *peers);
  20. void peers_register_table(struct peers *, struct stktable *table);
  21. void peers_setup_frontend(struct proxy *fe);
  22. diff --git a/src/cfgparse.c b/src/cfgparse.c
  23. index d1474d4b..7414b60d 100644
  24. --- a/src/cfgparse.c
  25. +++ b/src/cfgparse.c
  26. @@ -9111,7 +9111,12 @@ out_uri_auth_compat:
  27. curpeers->peers_fe = NULL;
  28. }
  29. else {
  30. - peers_init_sync(curpeers);
  31. + if (!peers_init_sync(curpeers)) {
  32. + ha_alert("Peers section '%s': out of memory, giving up on peers.\n",
  33. + curpeers->id);
  34. + cfgerr++;
  35. + break;
  36. + }
  37. last = &curpeers->next;
  38. continue;
  39. }
  40. diff --git a/src/peers.c b/src/peers.c
  41. index c56ed3af..0cd56da3 100644
  42. --- a/src/peers.c
  43. +++ b/src/peers.c
  44. @@ -2159,9 +2159,9 @@ static struct task *process_peer_sync(struct task * task)
  45. /*
  46. - *
  47. + * returns 0 in case of error.
  48. */
  49. -void peers_init_sync(struct peers *peers)
  50. +int peers_init_sync(struct peers *peers)
  51. {
  52. struct peer * curpeer;
  53. struct listener *listener;
  54. @@ -2173,10 +2173,14 @@ void peers_init_sync(struct peers *peers)
  55. list_for_each_entry(listener, &peers->peers_fe->conf.listeners, by_fe)
  56. listener->maxconn = peers->peers_fe->maxconn;
  57. peers->sync_task = task_new(MAX_THREADS_MASK);
  58. + if (!peers->sync_task)
  59. + return 0;
  60. +
  61. peers->sync_task->process = process_peer_sync;
  62. peers->sync_task->context = (void *)peers;
  63. peers->sighandler = signal_register_task(0, peers->sync_task, 0);
  64. task_wakeup(peers->sync_task, TASK_WOKEN_INIT);
  65. + return 1;
  66. }