Fix a bug in AST_SCHED_REPLACE_UNREF(). The reference count of the object

_must_ be increased before creating the scheduler entry.  Otherwise, you
create a race condition where the reference count may hit zero and the
object can disappear out from under you.  This could also would have
incorrectly decreased the reference count in the case that the scheduler
add failed.


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@152887 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Russell Bryant
2008-10-30 19:28:06 +00:00
parent c0b9b259ca
commit 694dd34413

View File

@@ -113,11 +113,10 @@ extern "C" {
unrefcall; /* should ref _data! */ \ unrefcall; /* should ref _data! */ \
if (_count == 10) \ if (_count == 10) \
ast_log(LOG_WARNING, "Unable to cancel schedule ID %d. This is probably a bug (%s: %s, line %d).\n", id, __FILE__, __PRETTY_FUNCTION__, __LINE__); \ ast_log(LOG_WARNING, "Unable to cancel schedule ID %d. This is probably a bug (%s: %s, line %d).\n", id, __FILE__, __PRETTY_FUNCTION__, __LINE__); \
refcall; \
id = ast_sched_add_variable(sched, when, callback, data, variable); \ id = ast_sched_add_variable(sched, when, callback, data, variable); \
if (id == -1) \ if (id == -1) \
addfailcall; \ addfailcall; \
else \
refcall; \
} while (0); } while (0);
#define AST_SCHED_REPLACE_UNREF(id, sched, when, callback, data, unrefcall, addfailcall, refcall) \ #define AST_SCHED_REPLACE_UNREF(id, sched, when, callback, data, unrefcall, addfailcall, refcall) \