0020-Fixed-2172-Avoid-double-reference-counter-decrements.patch 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. From 1fed39fe1488abd654a5488b5e6ad59b4b973331 Mon Sep 17 00:00:00 2001
  2. From: nanang <nanang@localhost>
  3. Date: Tue, 8 Jan 2019 09:07:47 +0000
  4. Subject: [PATCH 1/5] Fixed #2172: Avoid double reference counter decrements in
  5. timer in the scenario of race condition between pj_timer_heap_cancel() and
  6. pj_timer_heap_poll().
  7. ---
  8. pjlib/src/pj/timer.c | 17 ++++++++++-------
  9. 1 file changed, 10 insertions(+), 7 deletions(-)
  10. diff --git a/pjlib/src/pj/timer.c b/pjlib/src/pj/timer.c
  11. index 90a95e37b..7bae084ef 100644
  12. --- a/pjlib/src/pj/timer.c
  13. +++ b/pjlib/src/pj/timer.c
  14. @@ -580,13 +580,16 @@ static int cancel_timer(pj_timer_heap_t *ht,
  15. lock_timer_heap(ht);
  16. count = cancel(ht, entry, flags | F_DONT_CALL);
  17. - if (flags & F_SET_ID) {
  18. - entry->id = id_val;
  19. - }
  20. - if (entry->_grp_lock) {
  21. - pj_grp_lock_t *grp_lock = entry->_grp_lock;
  22. - entry->_grp_lock = NULL;
  23. - pj_grp_lock_dec_ref(grp_lock);
  24. + if (count > 0) {
  25. + /* Timer entry found & cancelled */
  26. + if (flags & F_SET_ID) {
  27. + entry->id = id_val;
  28. + }
  29. + if (entry->_grp_lock) {
  30. + pj_grp_lock_t *grp_lock = entry->_grp_lock;
  31. + entry->_grp_lock = NULL;
  32. + pj_grp_lock_dec_ref(grp_lock);
  33. + }
  34. }
  35. unlock_timer_heap(ht);
  36. --
  37. 2.20.1